Skip to content

Commit

Permalink
Merge pull request #1062 from sebastianbarry/rewrite-infinite-scroll-…
Browse files Browse the repository at this point in the history
…filters

✍️📂 Rewrite Infinite Scroll Filters (Multilabel + Enketo)
  • Loading branch information
shankari authored Oct 19, 2023
2 parents e60857f + 259778a commit d032ed1
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 116 deletions.
2 changes: 0 additions & 2 deletions www/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
3 changes: 1 addition & 2 deletions www/js/diary.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions www/js/diary/LabelTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
40 changes: 0 additions & 40 deletions www/js/survey/enketo/infinite_scroll_filters.js

This file was deleted.

38 changes: 38 additions & 0 deletions www/js/survey/enketo/infinite_scroll_filters.ts
Original file line number Diff line number Diff line change
@@ -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
];
67 changes: 0 additions & 67 deletions www/js/survey/multilabel/infinite_scroll_filters.js

This file was deleted.

58 changes: 58 additions & 0 deletions www/js/survey/multilabel/infinite_scroll_filters.ts
Original file line number Diff line number Diff line change
@@ -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
];
9 changes: 6 additions & 3 deletions www/js/survey/survey.ts
Original file line number Diff line number Diff line change
@@ -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<any>, 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"
}
Expand Down

0 comments on commit d032ed1

Please sign in to comment.