diff --git a/www/index.js b/www/index.js index 89c3a5e26..72d079b84 100644 --- a/www/index.js +++ b/www/index.js @@ -17,12 +17,10 @@ import './js/services.js'; import './js/i18n-utils.js'; import './js/main.js'; import './js/survey/input-matcher.js'; -import './js/survey/multilabel/infinite_scroll_filters.js'; import './js/survey/multilabel/multi-label-ui.js'; import './js/diary.js'; import './js/diary/services.js'; import './js/survey/enketo/answer.js'; -import './js/survey/enketo/infinite_scroll_filters.js'; import './js/survey/enketo/enketo-trip-button.js'; import './js/survey/enketo/enketo-add-note-button.js'; import './js/control/emailService.js'; diff --git a/www/js/diary.js b/www/js/diary.js index 3a150cfff..c0b7bce35 100644 --- a/www/js/diary.js +++ b/www/js/diary.js @@ -3,9 +3,8 @@ import LabelTab from './diary/LabelTab'; angular.module('emission.main.diary',['emission.main.diary.services', 'emission.survey.multilabel.buttons', - 'emission.survey.multilabel.infscrollfilters', 'emission.survey.enketo.add-note-button', - 'emission.survey.enketo.trip.infscrollfilters', + 'emission.survey.enketo.trip.button', 'emission.plugin.logger']) .config(function($stateProvider) { diff --git a/www/js/diary/LabelTab.tsx b/www/js/diary/LabelTab.tsx index bb2430481..f4677766d 100644 --- a/www/js/diary/LabelTab.tsx +++ b/www/js/diary/LabelTab.tsx @@ -68,8 +68,8 @@ const LabelTab = () => { // https://github.com/e-mission/e-mission-docs/issues/894 if (appConfig.survey_info?.buttons == undefined) { // initalize filters - const tripFilterFactory = getAngularService(surveyOpt.filter); - const allFalseFilters = tripFilterFactory.configuredFilters.map((f, i) => ({ + const tripFilter = surveyOpt.filter; + const allFalseFilters = tripFilter.map((f, i) => ({ ...f, state: (i == 0 ? true : false) // only the first filter will have state true on init })); setFilterInputs(allFalseFilters); diff --git a/www/js/survey/enketo/infinite_scroll_filters.js b/www/js/survey/enketo/infinite_scroll_filters.js deleted file mode 100644 index 8e45db8e4..000000000 --- a/www/js/survey/enketo/infinite_scroll_filters.js +++ /dev/null @@ -1,40 +0,0 @@ -'use strict'; - -/* - * The general structure of this code is that all the timeline information for - * a particular day is retrieved from the Timeline factory and put into the scope. - * For best performance, all data should be loaded into the in-memory timeline, - * and in addition to writing to storage, the data should be written to memory. - * All UI elements should only use $scope variables. - */ - -import angular from 'angular'; - -angular.module('emission.survey.enketo.trip.infscrollfilters',[ - 'emission.survey.enketo.trip.button', - 'emission.plugin.logger' - ]) -.factory('EnketoTripInfScrollFilters', function(Logger, EnketoTripButtonService){ - var sf = {}; - var unlabeledCheck = function(t) { - return !angular.isDefined(t.userInput[EnketoTripButtonService.SINGLE_KEY]); - } - - sf.UNLABELED = { - key: "unlabeled", - text: i18next.t("diary.unlabeled"), - filter: unlabeledCheck - } - - sf.TO_LABEL = { - key: "to_label", - text: i18next.t("diary.to-label"), - filter: unlabeledCheck - } - - sf.configuredFilters = [ - sf.TO_LABEL, - sf.UNLABELED, - ]; - return sf; -}); diff --git a/www/js/survey/enketo/infinite_scroll_filters.ts b/www/js/survey/enketo/infinite_scroll_filters.ts new file mode 100644 index 000000000..98eba65db --- /dev/null +++ b/www/js/survey/enketo/infinite_scroll_filters.ts @@ -0,0 +1,38 @@ +/* + * The general structure of this code is that all the timeline information for + * a particular day is retrieved from the Timeline factory and put into the scope. + * For best performance, all data should be loaded into the in-memory timeline, + * and in addition to writing to storage, the data should be written to memory. + * All UI elements should only use $scope variables. + */ + +import i18next from "i18next"; +import { getAngularService } from "../../angular-react-helper"; + +const unlabeledCheck = (t) => { + try { + const EnketoTripButtonService = getAngularService("EnketoTripButtonService"); + const etbsSingleKey = EnketoTripButtonService.SINGLE_KEY; + return typeof t.userInput[etbsSingleKey] === 'undefined'; + } + catch (e) { + console.log("Error in retrieving EnketoTripButtonService: ", e); + } +} + +const UNLABELED = { + key: "unlabeled", + text: i18next.t("diary.unlabeled"), + filter: unlabeledCheck +} + +const TO_LABEL = { + key: "to_label", + text: i18next.t("diary.to-label"), + filter: unlabeledCheck +} + +export const configuredFilters = [ + TO_LABEL, + UNLABELED +]; \ No newline at end of file diff --git a/www/js/survey/multilabel/infinite_scroll_filters.js b/www/js/survey/multilabel/infinite_scroll_filters.js deleted file mode 100644 index bc588ecc2..000000000 --- a/www/js/survey/multilabel/infinite_scroll_filters.js +++ /dev/null @@ -1,67 +0,0 @@ -'use strict'; - -/* - * The general structure of this code is that all the timeline information for - * a particular day is retrieved from the Timeline factory and put into the scope. - * For best performance, all data should be loaded into the in-memory timeline, - * and in addition to writing to storage, the data should be written to memory. - * All UI elements should only use $scope variables. - */ - -import angular from 'angular'; - -angular.module('emission.survey.multilabel.infscrollfilters',[ - 'emission.plugin.logger' - ]) -.factory('MultiLabelInfScrollFilters', function(Logger){ - var sf = {}; - var unlabeledCheck = function(t) { - return t.INPUTS - .map((inputType, index) => !angular.isDefined(t.userInput[inputType])) - .reduce((acc, val) => acc || val, false); - } - - var invalidCheck = function(t) { - const retVal = - (angular.isDefined(t.userInput['MODE']) && t.userInput['MODE'].value === 'pilot_ebike') && - (!angular.isDefined(t.userInput['REPLACED_MODE']) || - t.userInput['REPLACED_MODE'].value === 'pilot_ebike' || - t.userInput['REPLACED_MODE'].value === 'same_mode'); - return retVal; - } - - var toLabelCheck = function(trip) { - if (angular.isDefined(trip.expectation)) { - console.log(trip.expectation.to_label) - return trip.expectation.to_label && unlabeledCheck(trip); - } else { - return true; - } - } - - sf.UNLABELED = { - key: "unlabeled", - text: i18next.t("diary.unlabeled"), - filter: unlabeledCheck, - width: "col-50" - } - - sf.INVALID_EBIKE = { - key: "invalid_ebike", - text: i18next.t("diary.invalid-ebike"), - filter: invalidCheck - } - - sf.TO_LABEL = { - key: "to_label", - text: i18next.t("diary.to-label"), - filter: toLabelCheck, - width: "col-50" - } - - sf.configuredFilters = [ - sf.TO_LABEL, - sf.UNLABELED - ]; - return sf; -}); diff --git a/www/js/survey/multilabel/infinite_scroll_filters.ts b/www/js/survey/multilabel/infinite_scroll_filters.ts new file mode 100644 index 000000000..8d71266d9 --- /dev/null +++ b/www/js/survey/multilabel/infinite_scroll_filters.ts @@ -0,0 +1,58 @@ +/* + * The general structure of this code is that all the timeline information for + * a particular day is retrieved from the Timeline factory and put into the scope. + * For best performance, all data should be loaded into the in-memory timeline, + * and in addition to writing to storage, the data should be written to memory. + * All UI elements should only use $scope variables. + */ + +import i18next from "i18next"; + +const unlabeledCheck = (t) => { + return t.INPUTS + .map((inputType, index) => !t.userInput[inputType]) + .reduce((acc, val) => acc || val, false); +} + +const invalidCheck = (t) => { + const retVal = + (t.userInput['MODE'] && t.userInput['MODE'].value === 'pilot_ebike') && + (!t.userInput['REPLACED_MODE'] || + t.userInput['REPLACED_MODE'].value === 'pilot_ebike' || + t.userInput['REPLACED_MODE'].value === 'same_mode'); + return retVal; +} + +const toLabelCheck = (trip) => { + if (trip.expectation) { + console.log(trip.expectation.to_label) + return trip.expectation.to_label && unlabeledCheck(trip); + } else { + return true; + } +} + +const UNLABELED = { + key: "unlabeled", + text: i18next.t("diary.unlabeled"), + filter: unlabeledCheck, + width: "col-50" +} + +const INVALID_EBIKE = { + key: "invalid_ebike", + text: i18next.t("diary.invalid-ebike"), + filter: invalidCheck +} + +const TO_LABEL = { + key: "to_label", + text: i18next.t("diary.to-label"), + filter: toLabelCheck, + width: "col-50" +} + +export const configuredFilters = [ + TO_LABEL, + UNLABELED +]; \ No newline at end of file diff --git a/www/js/survey/survey.ts b/www/js/survey/survey.ts index e6692983f..66f662082 100644 --- a/www/js/survey/survey.ts +++ b/www/js/survey/survey.ts @@ -1,12 +1,15 @@ -type SurveyOption = { filter: string, service: string, elementTag: string } +import { configuredFilters as multilabelConfiguredFilters } from "./multilabel/infinite_scroll_filters"; +import { configuredFilters as enketoConfiguredFilters } from "./enketo/infinite_scroll_filters"; + +type SurveyOption = { filter: Array, service: string, elementTag: string } export const SurveyOptions: {[key: string]: SurveyOption} = { MULTILABEL: { - filter: "MultiLabelInfScrollFilters", + filter: multilabelConfiguredFilters, service: "MultiLabelService", elementTag: "multilabel" }, ENKETO: { - filter: "EnketoTripInfScrollFilters", + filter: enketoConfiguredFilters, service: "EnketoTripButtonService", elementTag: "enketo-trip-button" }