Skip to content

Commit

Permalink
Merge branch 'develop' into bug/1130-missing-sidebar-on-profile-page
Browse files Browse the repository at this point in the history
  • Loading branch information
ifirmawan authored Feb 6, 2024
2 parents f051998 + 4c590be commit efb2edd
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 84 deletions.
34 changes: 2 additions & 32 deletions backend/api/v1/v1_mobile/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from api.v1.v1_forms.models import Forms
from drf_spectacular.types import OpenApiTypes
from api.v1.v1_mobile.authentication import MobileAssignmentToken
from api.v1.v1_profile.models import Administration, Levels, Entity
from api.v1.v1_profile.models import Administration, Entity
from utils.custom_serializer_fields import CustomCharField
from api.v1.v1_mobile.models import MobileAssignment, MobileApk
from utils.custom_helper import CustomPasscode, generate_random_string
Expand All @@ -24,18 +24,6 @@ class Meta:
fields = ["id", "name", "url"]


class MobileAssignmentAdministrationSerializer(serializers.ModelSerializer):
id = serializers.IntegerField()
name = serializers.SerializerMethodField()

def get_name(self, obj):
return obj.full_path_name

class Meta:
model = Administration
fields = ["id", "name"]


class MobileFormSerializer(serializers.ModelSerializer):
id = serializers.IntegerField()
version = serializers.CharField()
Expand All @@ -55,29 +43,11 @@ class MobileAssignmentFormsSerializer(serializers.Serializer):
name = serializers.CharField(read_only=True)
syncToken = serializers.SerializerMethodField()
formsUrl = serializers.SerializerMethodField()
administrations = serializers.SerializerMethodField()

@extend_schema_field(MobileFormSerializer(many=True))
def get_formsUrl(self, obj):
return MobileFormSerializer(obj.forms.all(), many=True).data

@extend_schema_field(MobileAssignmentAdministrationSerializer(many=True))
def get_administrations(self, obj):
lowest_level = Levels.objects.order_by("-level").first()
all_lowest_levels = []
for adm in obj.administrations.all():
if adm.level == lowest_level:
all_lowest_levels.append(adm)
continue
administration = Administration.objects.filter(
path__startswith=adm.path,
level=lowest_level,
).all()
all_lowest_levels.extend(administration)
return MobileAssignmentAdministrationSerializer(
all_lowest_levels, many=True
).data

def get_syncToken(self, obj):
return str(MobileAssignmentToken.for_assignment(obj))

Expand All @@ -88,7 +58,7 @@ def validate_code(self, value):
return value

class Meta:
fields = ["name", "syncToken", "formsUrl", "code", "administrations"]
fields = ["name", "syncToken", "formsUrl", "code"]


class IdAndNameRelatedField(serializers.PrimaryKeyRelatedField):
Expand Down
8 changes: 0 additions & 8 deletions backend/api/v1/v1_mobile/tests/tests_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@ def test_mobile_assignment_form_api(self):
token = MobileAssignmentToken(syncToken)

self.assertEqual(token.assignment.id, self.mobile_assignment.id)
paths = [
f'{adm.path}{adm.id}.' for adm in self.administration_children
]
# administration should only shows the lowest level
self.assertEqual(
len(response.data['administrations']),
Administration.objects.filter(path__in=paths).count(),
)

self.assertEqual(
dict(response.data['formsUrl'][0]),
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
.table-wrapper {
background-color: white;
padding: 24px;

width: 100%;
.ant-form {
&.ant-form-horizontal {
.ant-form-item {
Expand Down
87 changes: 44 additions & 43 deletions frontend/src/pages/control-center/ControlCenter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,22 @@ const ControlCenter = () => {
key: "approvals",
access: "approvals",
render: (
<Col key="approvals-panel" span={24}>
<PanelApprovals />
</Col>
<div className="table-wrapper">
<Col key="approvals-panel" span={24}>
<PanelApprovals />
</Col>
</div>
),
},
{
key: "submission",
access: "form",
render: (
<Col key="submission-panel" span={24}>
<PanelSubmissions />
</Col>
<div className="table-wrapper">
<Col key="submission-panel" span={24}>
<PanelSubmissions />
</Col>
</div>
),
},
];
Expand All @@ -46,7 +50,6 @@ const ControlCenter = () => {
if (!authUser?.role_detail) {
return [];
}

const panelOrder = roles.find(
(r) => r.id === authUser.role_detail.id
)?.control_center_order;
Expand Down Expand Up @@ -107,44 +110,42 @@ const ControlCenter = () => {
</div>
</div>
<div className="table-section">
<div className="table-wrapper">
<Row gutter={[16, 32]}>
{selectedPanels.map((panel, index) => {
if (panel?.render) {
return panel.render;
}
const cardOnly = selectedPanels.filter((x) => !x?.render);
const isFullWidth =
cardOnly.length === 1 ||
(selectedPanels.length % 2 === 1 &&
selectedPanels.length - 1 === index);
return (
<Col
className="card-wrapper"
span={isFullWidth ? 24 : 12}
key={index}
>
<div hoverable>
<div className="row">
<div className="flex-1">
<h2>{panel?.title}</h2>
<span>{panel?.description}</span>
<Link to={panel?.link} className="explore">
<Button type="primary" shape="round">
{panel?.buttonLabel}
</Button>
</Link>
</div>
<div>
<img src={panel?.image} width={100} height={100} />
</div>
<Row gutter={[16, 32]}>
{selectedPanels.map((panel, index) => {
if (panel?.render) {
return panel.render;
}
const cardOnly = selectedPanels.filter((x) => !x?.render);
const isFullWidth =
cardOnly.length === 1 ||
(selectedPanels.length % 2 === 1 &&
selectedPanels.length - 1 === index);
return (
<Col
className="card-wrapper"
span={isFullWidth ? 24 : 12}
key={index}
>
<div hoverable>
<div className="row">
<div className="flex-1">
<h2>{panel?.title}</h2>
<span>{panel?.description}</span>
<Link to={panel?.link} className="explore">
<Button type="primary" shape="round">
{panel?.buttonLabel}
</Button>
</Link>
</div>
<div>
<img src={panel?.image} width={100} height={100} />
</div>
</div>
</Col>
);
})}
</Row>
</div>
</div>
</Col>
);
})}
</Row>
</div>
</>
);
Expand Down

0 comments on commit efb2edd

Please sign in to comment.