Skip to content

Commit

Permalink
Added barriers, indicators, opportunities and partners to settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
driver-deploy-2 committed Nov 8, 2024
1 parent f464577 commit f3cb41a
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 270 deletions.
2 changes: 2 additions & 0 deletions packages/gui/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import { LANGUAGE, SAVED } from './utils';
import { Languages, i18n } from './services';
import { registerPlugin } from 'mithril-ui-form';
import { SimpleListEditorPlugin } from './components/ui/simple-list-editor';
import { searchSelectPlugin } from './components/ui/search-select-plugin';

registerPlugin('list', SimpleListEditorPlugin);
registerPlugin('search_select', searchSelectPlugin);

document.documentElement.setAttribute('lang', 'en');

Expand Down
66 changes: 32 additions & 34 deletions packages/gui/src/components/settings-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import { Collapsible, FlatButton, Tabs } from 'mithril-materialized';
import { attrForm, AttributeType } from '../models/forms';
import { TextInputWithClear } from './ui/text-input-with-clear';

type ItemType = 'cast' | 'attribute' | 'location' | 'geolocation' | 'transport' | 'product';

export const SettingsPage: MeiosisComponent = () => {
let edit = false;
let storedModel: DataModel;
Expand Down Expand Up @@ -70,68 +68,68 @@ export const SettingsPage: MeiosisComponent = () => {
[
'attributes',
t('ATTRIBUTES'),
'attribute',
'attributes',
'build',
attributes.filter((a) => !labelFilter || (a.label && a.label.toLowerCase().includes(labelFilter))),
],
[
'products',
t('PRODUCTS', 2),
'product',
'products',
'shopping_bag',
products.filter((a) => !labelFilter || (a.label && a.label.toLowerCase().includes(labelFilter))),
],
[
'transports',
t('TRANSPORTS'),
'transport',
'transports',
'directions',
transports.filter((a) => !labelFilter || (a.label && a.label.toLowerCase().includes(labelFilter))),
],
[
'locations',
t('LOCATIONS', 2),
'locations',
'warehouse',
locations.filter((a) => !labelFilter || (a.label && a.label.toLowerCase().includes(labelFilter))),
],
[
'geoLocations',
t('GEOLOCATIONS', 2),
'geoLocations',
'location_on',
geoLocations.filter((a) => !labelFilter || (a.label && a.label.toLowerCase().includes(labelFilter))),
],
[
'opportunities',
t('OPPORTUNITIES'),
'opportunity',
'opportunities',
'lightbulb',
opportunities.filter((a) => !labelFilter || (a.label && a.label.toLowerCase().includes(labelFilter))),
],
[
'partners',
t('PARTNERS'),
'partner',
'handshake', // groups
partners.filter((a) => !labelFilter || (a.label && a.label.toLowerCase().includes(labelFilter))),
],
[
'indicators',
t('INDICATORS'),
'indicator',
'indicators',
'light_mode',
indicators.filter((a) => !labelFilter || (a.label && a.label.toLowerCase().includes(labelFilter))),
],
[
'partners',
t('PARTNERS'),
'partners',
'handshake', // groups
partners.filter((a) => !labelFilter || (a.label && a.label.toLowerCase().includes(labelFilter))),
],
[
'barriers',
t('BARRIERS'),
'barrier',
'barriers',
'block',
barriers.filter((a) => !labelFilter || (a.label && a.label.toLowerCase().includes(labelFilter))),
],
[
'locations',
t('LOCATIONS', 2),
'location',
'warehouse',
locations.filter((a) => !labelFilter || (a.label && a.label.toLowerCase().includes(labelFilter))),
],
[
'geoLocations',
t('GEOLOCATIONS', 2),
'geolocation',
'location_on',
geoLocations.filter((a) => !labelFilter || (a.label && a.label.toLowerCase().includes(labelFilter))),
],
] as Array<
[id: AttributeType, label: string, type: ItemType, iconName: string, attrs: Array<Hierarchical & Labeled>]
[id: AttributeType, label: string, type: AttributeType, iconName: string, attrs: Array<Hierarchical & Labeled>]
>;

return m(
Expand Down Expand Up @@ -181,7 +179,7 @@ export const SettingsPage: MeiosisComponent = () => {
title: `${attr.length ? `${attr.length} ` : ''}${label}`,
vnode: edit
? m(LayoutForm, {
form: attrForm(id, label, attr),
form: attrForm(id, label, type === 'barriers' ? partners : attr, type),
obj: model,
} as FormAttributes<any>)
: m(AttrView, {
Expand All @@ -202,7 +200,7 @@ export const SettingsPage: MeiosisComponent = () => {

const AttrView: FactoryComponent<{
attr: Array<Hierarchical & Labeled>;
type: ItemType;
type: AttributeType;
iconName?: string;
acts: Act[];
crimeScripts: CrimeScript[];
Expand All @@ -223,7 +221,7 @@ const AttrView: FactoryComponent<{
if (actIdx < 0) return;
const act = acts[actIdx];
[{ ...act }].forEach((phase, phaseIdx) => {
if (type === 'location') {
if (type === 'locations') {
if (phase.locationIds) {
acc.push([crimeScriptIdx, actIdx, phaseIdx, SearchScore.EXACT_MATCH]);
}
Expand All @@ -234,7 +232,7 @@ const AttrView: FactoryComponent<{
if (cast.includes(c.id)) {
acc.push([crimeScriptIdx, actIdx, phaseIdx, SearchScore.EXACT_MATCH]);
}
} else if (type === 'attribute') {
} else if (type === 'attributes') {
const { attributes = [] } = activity;
if (attributes.includes(c.id)) {
acc.push([crimeScriptIdx, actIdx, phaseIdx, SearchScore.EXACT_MATCH]);
Expand Down
108 changes: 52 additions & 56 deletions packages/gui/src/components/ui/crime-script-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ import {
ActivityType,
Product,
} from '../../models';
import { FlatButton, Tabs, uniqueId, Select, ISelectOptions } from 'mithril-materialized';
import { FlatButton, Tabs, uniqueId, Select, ISelectOptions, SearchSelect } from 'mithril-materialized';
import { FormAttributes, LayoutForm, UIForm } from 'mithril-ui-form';
import { labelForm, literatureForm } from '../../models/forms';
import { MultiSelectDropdown } from '../ui/multi-select';
import { crimeMeasureOptions } from '../../models/situational-crime-prevention';
import { I18N, t } from '../../services/translations';
import { InputOptions, toOptions } from '../../utils';
Expand Down Expand Up @@ -192,64 +191,61 @@ export const CrimeScriptEditor: FactoryComponent<{
i18n: I18N,
} as FormAttributes<Partial<CrimeScript>>),

curActIds &&
curActIds && [
m(
'.col.s12',
m('.row', [
m(
'.col.s12',
m(MultiSelectDropdown, {
items: acts,
selectedIds: curActIds.ids,
label: t('SELECT_ACT_N'),
max: 5,
search: true,
selectAll: false,
listAll: true,
onchange: (selectedIds) => {
crimeScript.stages[curActIdx] = {
id: selectedIds.length > 0 ? selectedIds[0] : '',
ids: selectedIds,
};
m.redraw();
},
})
),
curActIds.ids &&
curActIds.ids.length > 0 && [
m(Select, {
key: curAct ? curAct.label : curActIds.id,
label: t('SELECT_ACT'),
className: 'col s6',
initialValue: curActIds.id,
// disabled: curActIds.ids.length === 1,
options: acts.filter((a) => curActIds.ids.includes(a.id)),
onchange: (id) => {
crimeScript.stages[curActIdx].id = id[0];
},
} as ISelectOptions<ID>),
],
m(FlatButton, {
label: t('ACT'),
m(SearchSelect<string>, {
key: curAct ? curAct.id : '',
label: t('SELECT_ACT_N'),
options: acts,
initialValue: curActIds.ids,
// max: 5,
// search: true,
// selectAll: false,
// listAll: true,
onchange: (selectedIds) => {
crimeScript.stages[curActIdx] = {
id: selectedIds.length > 0 ? selectedIds[0] : '',
ids: selectedIds,
};
// m.redraw();
},
})
),
curActIds.ids &&
curActIds.ids.length > 0 && [
m(Select, {
key: curAct ? curAct.label : curActIds.id,
label: t('SELECT_ACT'),
className: 'col s6',
iconName: 'add',
onclick: () => {
const id = uniqueId();
const newAct = {
id,
label: t('ACT'),
} as Act;
acts.push(newAct);
crimeScript.stages[curActIdx].id = id;
if (crimeScript.stages[curActIdx].ids) {
crimeScript.stages[curActIdx].ids.push(id);
} else {
crimeScript.stages[curActIdx].ids = [id];
}
initialValue: curActIds.id,
// disabled: curActIds.ids.length === 1,
options: acts.filter((a) => curActIds.ids.includes(a.id)),
onchange: (id) => {
crimeScript.stages[curActIdx].id = id[0];
},
}),
])
),
} as ISelectOptions<ID>),
],
m(FlatButton, {
label: t('ACT'),
className: 'col s6',
iconName: 'add',
onclick: () => {
const id = uniqueId();
const newAct = {
id,
label: t('ACT'),
} as Act;
acts.push(newAct);
crimeScript.stages[curActIdx].id = id;
if (crimeScript.stages[curActIdx].ids) {
crimeScript.stages[curActIdx].ids.push(id);
} else {
crimeScript.stages[curActIdx].ids = [id];
}
},
}),
],

curAct && [
m('.cur-act', { key: curAct.id }, [
Expand Down
Loading

0 comments on commit f3cb41a

Please sign in to comment.