Skip to content

Commit

Permalink
Close #10 Add product, geo, loc, to editor
Browse files Browse the repository at this point in the history
  • Loading branch information
driver-deploy-2 committed Sep 17, 2024
1 parent f4b7334 commit 07ddd6d
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 75 deletions.
32 changes: 26 additions & 6 deletions packages/gui/src/components/crime-script-page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import m from 'mithril';
import { CrimeScript, Pages, scriptIcon } from '../models';
import { MeiosisComponent, routingSvc } from '../services';
import { FlatButton, uniqueId, ModalPanel, Icon } from 'mithril-materialized';
import { CrimeScript, Pages } from '../models';
import { MeiosisComponent } from '../services';
import { FlatButton, ModalPanel } from 'mithril-materialized';
import { t } from '../services/translations';
import { toWord } from '../utils/word';
import { formatDate } from '../utils';
Expand All @@ -22,7 +22,16 @@ export const CrimeScriptPage: MeiosisComponent = () => {
},
view: ({ attrs: { state, actions } }) => {
const { model, role, curActIdx, curPhaseIdx, currentCrimeScriptId = '' } = state;
const { crimeScripts = [], cast = [], acts = [], attributes = [], locations = [] } = model;
const {
crimeScripts = [],
cast = [],
acts = [],
attributes = [],
locations = [],
geoLocations = [],
transports = [],
products = [],
} = model;
id = m.route.param('id') || currentCrimeScriptId || (crimeScripts.length > 0 ? crimeScripts[0].id : '');
const crimeScript =
crimeScripts.find((c) => c.id === id) || (crimeScripts.length > 0 ? crimeScripts[0] : ({} as CrimeScript));
Expand Down Expand Up @@ -79,13 +88,24 @@ export const CrimeScriptPage: MeiosisComponent = () => {
m(
'.row.crime-scene',
edit
? m(CrimeScriptEditor, { crimeScript: crimeScript, cast, acts, attributes, locations })
? m(CrimeScriptEditor, {
crimeScript,
cast,
acts,
attributes,
locations,
geoLocations,
transports,
products,
})
: m(CrimeScriptViewer, {
crimeScript: crimeScript,
crimeScript,
cast,
acts,
attributes,
locations,
geoLocations,
products,
curActIdx,
curPhaseIdx,
update: actions.update,
Expand Down
2 changes: 1 addition & 1 deletion packages/gui/src/components/settings-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const AttrView: FactoryComponent<{
const act = acts[actIdx];
[act.preparation, act.preactivity, act.activity, act.postactivity].forEach((phase, phaseIdx) => {
if (type === 'location') {
if (phase.locationId) {
if (phase.locationIds) {
acc.push({
crimeScriptIdx,
actIdx,
Expand Down
87 changes: 63 additions & 24 deletions packages/gui/src/components/ui/crime-script-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Act,
Activity,
ActivityPhase,
ActivityTypeOptions,
Cast,
Condition,
CrimeScript,
Expand All @@ -13,28 +12,29 @@ import {
Stage,
Measure,
CrimeLocation,
Transport,
GeographicLocation,
ActivityType,
Product,
} from '../../models';
import { FlatButton, Tabs, uniqueId, Select, ISelectOptions } 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 { t } from '../../services/translations';
import { I18N, t } from '../../services/translations';
import { InputOptions, toOptions } from '../../utils';

export const CrimeScriptEditor: FactoryComponent<{
crimeScript: CrimeScript;
cast: Cast[];
acts: Act[];
transports: Transport[];
attributes: CrimeScriptAttributes[];
locations: CrimeLocation[];
geoLocations: GeographicLocation[];
products: Product[];
}> = () => {
type InputOptions = {
id: string;
label?: string;
group?: string;
icon?: string;
};

const actsForm: UIForm<any> = [
{
id: 'stages',
Expand All @@ -45,20 +45,32 @@ export const CrimeScriptEditor: FactoryComponent<{
},
];

let locationOptions: Array<InputOptions> = [];
let castOptions: Array<InputOptions> = [];
let attrOptions: Array<InputOptions> = [];
let locationOptions: InputOptions[] = [];
let geoLocationOptions: InputOptions[] = [];
let transportOptions: InputOptions[] = [];
let castOptions: InputOptions[] = [];
let attrOptions: InputOptions[] = [];
let productOptions: InputOptions[] = [];
let measuresForm: UIForm<any> = [];

const ActivityTypeOptions = [
// { id: ActivityType.NONE, label: 'None' },
{ id: ActivityType.HAS_CAST, label: t('CAST') },
{ id: ActivityType.HAS_ATTRIBUTES, label: t('ATTRIBUTES') },
{ id: ActivityType.HAS_TRANSPORT, label: t('TRANSPORTS') },
// { id: ActivityType.HAS_CAST_ATTRIBUTES, label: 'Both' },
];

return {
oninit: ({ attrs: { cast, attributes, locations } }) => {
castOptions = cast.map(({ id, label }) => ({
id,
label,
group: 'person',
}));
attrOptions = attributes.map(({ id, label }) => ({ id, label }));
oninit: ({
attrs: { cast = [], attributes = [], locations = [], geoLocations = [], transports = [], products = [] },
}) => {
castOptions = toOptions(cast, true);
attrOptions = toOptions(attributes);
locationOptions = locations.map(({ id, label }) => ({ id, label }));
geoLocationOptions = toOptions(geoLocations);
transportOptions = toOptions(transports);
productOptions = toOptions(products);
const measOptions = crimeMeasureOptions();

const measureForm: UIForm<Measure> = [
Expand All @@ -73,11 +85,21 @@ export const CrimeScriptEditor: FactoryComponent<{
view: ({ attrs: { acts, crimeScript } }) => {
const activityForm: UIForm<any> = [
{
id: 'locationId',
id: 'locationIds',
type: 'select',
multiple: true,
label: t('LOCATION'),
className: 'col s6 m4',
options: locationOptions,
},
{
id: 'geoLocations',
type: 'select',
multiple: true,
label: t('GEOLOCATIONS'),
className: 'col s6 m4',
options: geoLocationOptions,
},
{
id: 'activities',
repeat: true,
Expand All @@ -94,22 +116,31 @@ export const CrimeScriptEditor: FactoryComponent<{
},
{
id: 'cast',
show: ['type=1', 'type=4'],
show: ['type=1'],
type: 'select',
className: 'col s12 m6',
className: 'col s12 m4',
multiple: true,
options: castOptions,
label: t('CAST'),
},
{
id: 'attributes',
show: ['type=2', 'type=4'],
show: ['type=2'],
type: 'select',
className: 'col s12 m6',
className: 'col s12 m4',
multiple: true,
options: attrOptions,
label: t('ATTRIBUTES'),
},
{
id: 'transports',
show: ['type=4'],
type: 'select',
className: 'col s12 m4',
multiple: true,
options: transportOptions,
label: t('TRANSPORTS'),
},
{
id: 'description',
label: t('DESCRIPTION'),
Expand Down Expand Up @@ -147,11 +178,13 @@ export const CrimeScriptEditor: FactoryComponent<{
m(LayoutForm, {
form: [
...labelForm(),
{ id: 'productIds', type: 'select', label: t('PRODUCTS'), multiple: true, options: productOptions },
{ id: 'literature', type: literatureForm(), repeat: true, label: t('REFERENCES') },
...actsForm,
],
obj: crimeScript,
onchange: () => {},
i18n: I18N,
} as FormAttributes<Partial<CrimeScript>>),

curActIds &&
Expand Down Expand Up @@ -228,6 +261,7 @@ export const CrimeScriptEditor: FactoryComponent<{
],
obj: curAct,
onchange: () => {},
i18n: I18N,
} as FormAttributes<Partial<Act>>),
m(Tabs, {
tabs: [
Expand All @@ -238,6 +272,7 @@ export const CrimeScriptEditor: FactoryComponent<{
form: activityForm,
obj: curAct.preparation,
onchange: () => {},
i18n: I18N,
} as FormAttributes<Partial<ActivityPhase>>),
]),
},
Expand All @@ -248,6 +283,7 @@ export const CrimeScriptEditor: FactoryComponent<{
form: activityForm,
obj: curAct.preactivity,
onchange: () => {},
i18n: I18N,
} as FormAttributes<Partial<ActivityPhase>>),
]),
},
Expand All @@ -258,6 +294,7 @@ export const CrimeScriptEditor: FactoryComponent<{
form: activityForm,
obj: curAct.activity,
onchange: () => {},
i18n: I18N,
} as FormAttributes<Partial<ActivityPhase>>),
]),
},
Expand All @@ -268,6 +305,7 @@ export const CrimeScriptEditor: FactoryComponent<{
form: activityForm,
obj: curAct.postactivity,
onchange: () => {},
i18n: I18N,
} as FormAttributes<Partial<ActivityPhase>>),
]),
},
Expand All @@ -280,6 +318,7 @@ export const CrimeScriptEditor: FactoryComponent<{
onchange: () => {
// console.log(curAct);
},
i18n: I18N,
} as FormAttributes<Partial<ActivityPhase>>),
]),
],
Expand Down
Loading

0 comments on commit 07ddd6d

Please sign in to comment.