Skip to content

Commit

Permalink
Improve and sanitaze code
Browse files Browse the repository at this point in the history
  • Loading branch information
lomamech committed Sep 16, 2019
1 parent d0e8b2a commit 6fcba2b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 29 deletions.
14 changes: 7 additions & 7 deletions client/src/modules/display_metadata/display_metadata.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
</a>
</li>


<!-- FIX ME TO DOWMLOAD AS CSV and EXCEL
<li role="menuitem">
<a>
Expand All @@ -37,7 +36,7 @@
</ul>
</div>
</div>
<div ng-if="DisplayMetadataCtrl.patientData">
<div ng-if="DisplayMetadataCtrl.hasPatientData">
<div class="toolbar-item">
<button class="btn btn-default text-capitalize" id="create" ui-sref="display_metadata.patientfill({id : DisplayMetadataCtrl.collector.id, patient: DisplayMetadataCtrl.patient.uuid})" data-method="create">
<span class="fa fa fa-file-text"></span> <span class="hidden-xs" translate>FORM.BUTTONS.FILL_FORM</span>
Expand Down Expand Up @@ -78,12 +77,12 @@
<div class="flex-util" style="overflow: auto" ng-if="DisplayMetadataCtrl.collector">
<span data="filter">
<span class="label" style="text-shadow: {{ DisplayMetadataCtrl.collector.color }} 5px 3px 8px; font-size: 15px; color: black">
<span> {{ DisplayMetadataCtrl.collector.label }} </span>
{{ DisplayMetadataCtrl.collector.label }}
</span>
</span>

<span ng-if="DisplayMetadataCtrl.filterElements" data="filter">
<span class="label" ng-class="{ 'label-primary' : true, 'label-emphasize' : true }">
<span class="label label-primary label-emphasize">
<i class="fa fa-filter"></i>
{{ DisplayMetadataCtrl.filterElements }}
<a href ng-click="DisplayMetadataCtrl.onRemove()" class="filter-text-link">
Expand All @@ -92,9 +91,9 @@
</span>
</span>

<span ng-if="DisplayMetadataCtrl.patientData" data="filter">
<span ng-if="DisplayMetadataCtrl.hasPatientData" data="filter">
<span class="label" style="font-size: 15px; color: black; text-shadow: gray 4px 1px 10px;">
<span>:{{ DisplayMetadataCtrl.patient.display_name }} / {{ DisplayMetadataCtrl.patient.reference}} </span>
<span>:{{ DisplayMetadataCtrl.patient.display_name }}/{{ DisplayMetadataCtrl.patient.reference}}</span>
</span>
</span>
</div>
Expand All @@ -104,7 +103,8 @@
<div id="display-metadata-grid"
ui-grid="DisplayMetadataCtrl.gridOptions"
class="grid-full-height-with-filters"
ui-grid-auto-resize
ui-grid-auto-resize
ui-grid-move-columns
ui-grid-resize-columns>

<bh-grid-loading-indicator
Expand Down
41 changes: 28 additions & 13 deletions client/src/modules/display_metadata/display_metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ function DisplayMetadataController($state, DisplayMetadata, DataCollectorManagem

if ($state.params.id && $state.params.patient) {
// Prevent a non-patient form from being used to collect non-patient data
vm.patientData = true;
vm.hasPatientData = true;
} else {
vm.patientData = false;
vm.hasPatientData = false;

if (vm.collectorId) {
loadGrid();
Expand Down Expand Up @@ -80,14 +80,14 @@ function DisplayMetadataController($state, DisplayMetadata, DataCollectorManagem
vm.remove = remove;

function edit(data) {
if (!$state.params.patient) {
$state.go('display_metadata.edit', { id : data.data_collector_management_id, uuid : data.uuid });
} else if ($state.params.patient) {
if (vm.hasPatientData) {
$state.go('display_metadata.patientEdit', {
id : data.data_collector_management_id,
uuid : data.uuid,
patient : $state.params.patient,
});
} else {
$state.go('display_metadata.edit', { id : data.data_collector_management_id, uuid : data.uuid });
}
}

Expand Down Expand Up @@ -115,9 +115,10 @@ function DisplayMetadataController($state, DisplayMetadata, DataCollectorManagem
if (cache.collector && !vm.collectorId && !$state.params.patient) {
vm.collectorId = cache.collector.id;
}
const changesLength = Object.keys(vm.changes).length;

if (cache.changes && !changesLength) {
const hasNoChanges = Object.keys(vm.changes).length === 0;

if (hasNoChanges) {
vm.changes = cache.changes;
}

Expand All @@ -127,6 +128,11 @@ function DisplayMetadataController($state, DisplayMetadata, DataCollectorManagem
vm.hasError = false;
vm.loading = true;

vm.params = {
data_collector_management_id : vm.collectorId,
changes : vm.changes,
};

SurveyForm.read(null, { data_collector_management_id : vm.collectorId })
.then((survey) => {
vm.filterElements = DisplayMetadata.displayFilters(survey, vm.changes);
Expand All @@ -137,14 +143,16 @@ function DisplayMetadataController($state, DisplayMetadata, DataCollectorManagem
filterClient : vm.filterElements,
};

vm.params = {
data_collector_management_id : vm.collectorId,
changes : vm.changes,
};

return DisplayMetadata.read(null, vm.params);
})
.then((data) => {
data.columns.forEach(item => {
if (item.field === 'dateSurvey') {
item.aggregationType = uiGridConstants.aggregationTypes.count;
item.aggregationHideLabel = true;
}
});

vm.gridOptions.columnDefs = data.columns;
vm.gridOptions.data = data.surveyData;

Expand All @@ -171,6 +179,13 @@ function DisplayMetadataController($state, DisplayMetadata, DataCollectorManagem

DisplayMetadata.read(null, vm.params)
.then((data) => {
data.columns.forEach(item => {
if (item.field === 'dateSurvey') {
item.aggregationType = uiGridConstants.aggregationTypes.count;
item.aggregationHideLabel = true;
}
});

vm.gridOptions.columnDefs = data.columns;
vm.gridOptions.data = data.surveyData;

Expand Down Expand Up @@ -205,7 +220,7 @@ function DisplayMetadataController($state, DisplayMetadata, DataCollectorManagem
vm.loading = false;
}

// search Payroll Data
// search Metadata of survey
function search() {
DisplayMetadata.openSearchModal()
.then((changes) => {
Expand Down
17 changes: 9 additions & 8 deletions client/src/modules/display_metadata/display_metadata.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function DisplayMetadataService(Api, Modal, moment, $translate, $httpParamSerial
}

function displayFilters(survey, search) {
let filters = ``;
let filters = [];
const surveyMap = new Map(survey.map(item => ([item.name, item])));
const dateLabel = $translate.instant('FORM.LABELS.DATE');

Expand All @@ -68,14 +68,14 @@ function DisplayMetadataService(Api, Modal, moment, $translate, $httpParamSerial
if (dateFromLength) {
Object.keys(search.searchDateFrom).forEach((key) => {
if (key === 'dateSurvey') {
filters += ` // ( ${dateLabel} [${moment(search.searchDateFrom[key]).format('DD MMM YYYY')}
- ${moment(search.searchDateTo[key]).format('DD MMM YYYY')}])`;
filters.push(`// ( ${dateLabel} [${moment(search.searchDateFrom[key]).format('DD MMM YYYY')}
- ${moment(search.searchDateTo[key]).format('DD MMM YYYY')}])`);
}

const item = surveyMap.get(key);
if (item) {
filters += ` // ( ${item.label} [${moment(search.searchDateFrom[key]).format('DD MMM YYYY')}
- ${moment(search.searchDateTo[key]).format('DD MMM YYYY')}])`;
filters.push(` // ( ${item.label} [${moment(search.searchDateFrom[key]).format('DD MMM YYYY')}
- ${moment(search.searchDateTo[key]).format('DD MMM YYYY')}])`);
}
});
}
Expand All @@ -85,7 +85,7 @@ function DisplayMetadataService(Api, Modal, moment, $translate, $httpParamSerial
search.loggedChanges.forEach(element => {
const item = surveyMap.get(element.key);
if (item) {
filters += ` // ${item.label} : ${element.value} `;
filters.push(` // ${item.label} : ${element.value} `);
}
});
}
Expand All @@ -101,13 +101,14 @@ function DisplayMetadataService(Api, Modal, moment, $translate, $httpParamSerial
multiChoice += ` ${search.multipleChoice[key][i]}, `;
}

filters += ` // ${item.label} : ( ${multiChoice} )`;
filters.push(` // ${item.label} : ( ${multiChoice} )`);
}
});
}
}

return filters;
const filtersElememts = filters.length ? filters.join(' ') : ``;
return filtersElememts;
}

return service;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<div ng-if="formItem.typeForm === 'select_one'">
<bh-choice-list-select
id="{{ formItem.name }}"
list="$ctrl.searchQueries[formItem.name]"
list="$ctrl.searchValues[formItem.name]"
name="{{ formItem.name }}"
list-label="{{ formItem.label }}"
list-hint="{{ formItem.hint }}"
Expand Down
2 changes: 2 additions & 0 deletions client/src/modules/display_metadata/modals/search.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function DisplayMetadataSearchModalController(
const vm = this;
vm.onSelectSurveyForm = onSelectSurveyForm;
vm.searchQueries = {};
vm.searchValues = {};
vm.searchDateFrom = {};
vm.searchDateTo = {};
vm.multipleChoice = {};
Expand All @@ -36,6 +37,7 @@ function DisplayMetadataSearchModalController(
}

function onSelectList(list, value) {
vm.searchValues[value] = list.id;
vm.searchQueries[value] = list.label;
}

Expand Down

0 comments on commit 6fcba2b

Please sign in to comment.