Skip to content

Commit c949ccb

Browse files
committed
Basically working
1 parent 8b73e30 commit c949ccb

File tree

13 files changed

+257
-62
lines changed

13 files changed

+257
-62
lines changed

app/Http/Controllers/EditorController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ public function addAttribute(Request $request) {
171171
'text' => 'string',
172172
'recursive' => 'nullable|boolean_string',
173173
'si_base' => 'nullable|si_baseunit',
174-
'si_default' => 'nullable|si_unit:si_base'
174+
'si_default' => 'nullable|si_unit:si_base',
175+
'metadata' => 'nullable|array',
175176
]);
176177

177178
$lid = $request->get('label_id');
@@ -180,6 +181,7 @@ public function addAttribute(Request $request) {
180181
$attr = new Attribute();
181182
$attr->thesaurus_url = $curl;
182183
$attr->datatype = $datatype;
184+
$attr->metadata = $request->get('metadata');
183185
$attr->recursive = $request->has('recursive') && sp_parse_boolean($request->get('recursive'));
184186
if($request->has('root_id')) {
185187
$pid = $request->get('root_id');

resources/js/api.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,10 @@ export async function addAttribute(attribute) {
477477
data.si_default = attribute.siGroupUnit;
478478
}
479479

480+
if(attribute.metadata) {
481+
data.metadata = attribute.metadata;
482+
}
483+
480484
return $httpQueue.add(
481485
() => http.post(`/editor/dm/attribute`, data).then(response => response.data)
482486
);

resources/js/bootstrap/i18n.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ export function getSupportedLanguages() {
2525
return Object.keys(messages);
2626
}
2727

28+
export const globalT = i18n.global.t;
29+
2830
export default i18n;

resources/js/components/AttributeTemplate.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@
221221
/>
222222
</div>
223223
</div>
224+
<EpochAttributeTemplate
225+
v-if="state.isEpoch"
226+
v-model="state.attribute"
227+
class="mb-3"
228+
/>
224229
<template v-if="state.isSiUnit">
225230
<div class="mb-3">
226231
<label class="col-form-label col-3">
@@ -339,11 +344,13 @@
339344
340345
import ChainList from './chain/ChainList.vue';
341346
import PluginBadge from './plugins/Badge.vue';
347+
import EpochAttributeTemplate from './attribute/template/EpochAttributeTemplate.vue';
342348
343349
export default {
344350
components: {
345351
ChainList,
346352
PluginBadge,
353+
EpochAttributeTemplate,
347354
},
348355
props: {
349356
type: {
@@ -408,6 +415,11 @@
408415
if(!state.canRestrictTypes || state.attribute.restrictedTypes.length == 0) {
409416
state.attribute.restrictedTypes = null;
410417
}
418+
419+
// TODO: Here happens an API call, if it fails all changes are lost.
420+
// The call should be evaluated first before the data is deleted!
421+
// E.g. pass the handler as a callback. When it succeeds, reset the form.
422+
// otherwise, show an error message.
411423
context.emit('created', { ...state.attribute });
412424
reset();
413425
};
@@ -547,6 +559,9 @@
547559
state.attribute.type == 'string-mc' ||
548560
state.attribute.type == 'epoch';
549561
}),
562+
isEpoch: computed(_ => {
563+
return state.attribute.type == 'epoch' || state.attribute.type == 'timeperiod';
564+
}),
550565
isStringSc: computed(_ => {
551566
return state.attribute.type == 'string-sc';
552567
}),
@@ -582,6 +597,8 @@
582597
}),
583598
});
584599
600+
watch(() => state.attribute.metadata, emitUpdate, { deep: true });
601+
585602
/**
586603
* We update the validated event with a watcher
587604
* to avoid side effects in the computed property.

resources/js/components/attribute/Attribute.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
:value="state.value"
8888
:epochs="state.selection"
8989
:type="data.datatype"
90+
:metadata="data.metadata"
9091
@change="updateDirtyState"
9192
/>
9293

resources/js/components/attribute/Epoch.vue

Lines changed: 28 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,11 @@
11
<template>
22
<div>
33
<div class="input-group">
4-
<button
5-
type="button"
6-
class="btn btn-outline-secondary dropdown-toggle"
7-
:disabled="disabled"
8-
data-bs-toggle="dropdown"
9-
aria-haspopup="true"
10-
aria-expanded="false"
11-
>
12-
<span v-if="v.startLabel.value">
13-
{{ t(`main.entity.attributes.${v.startLabel.value}`) }}
14-
</span>
15-
<span v-else>
16-
<!-- TODO: Check if this else is required -->
17-
</span>
18-
</button>
19-
<ul class="dropdown-menu">
20-
<a
21-
v-for="(label, i) in timeLabels"
22-
:key="i"
23-
class="dropdown-item"
24-
href="#"
25-
@click.prevent="setLabel('startLabel', label)"
26-
>
27-
{{ t(`main.entity.attributes.${label}`) }}
28-
</a>
29-
</ul>
4+
<common-era-dropdown
5+
:model-value="v.startLabel.value"
6+
:format="epochFormat"
7+
@update:modelValue="(value) => setLabel('startLabel', value)"
8+
/>
309
<input
3110
v-model.number="v.start.value"
3211
type="number"
@@ -50,35 +29,11 @@
5029
aria-label=""
5130
@input="v.end.handleInput"
5231
>
53-
<button
54-
type="button"
55-
class="btn btn-outline-secondary dropdown-toggle"
56-
:disabled="disabled"
57-
data-bs-toggle="dropdown"
58-
aria-haspopup="true"
59-
aria-expanded="false"
60-
>
61-
<span v-if="v.endLabel.value">
62-
{{ t(`main.entity.attributes.${v.endLabel.value}`) }}
63-
</span>
64-
<span v-else>
65-
<!-- TODO: Check if this else is required -->
66-
</span>
67-
</button>
68-
<ul
69-
uib-dropdown-menu
70-
class="dropdown-menu"
71-
>
72-
<a
73-
v-for="(label, i) in timeLabels"
74-
:key="i"
75-
class="dropdown-item"
76-
href="#"
77-
@click.prevent="setLabel('endLabel', label)"
78-
>
79-
{{ t(`main.entity.attributes.${label}`) }}
80-
</a>
81-
</ul>
32+
<common-era-dropdown
33+
:model-value="v.endLabel.value"
34+
:format="epochFormat"
35+
@update:modelValue="(value) => setLabel('endLabel', value)"
36+
/>
8237
</div>
8338
<multiselect
8439
v-if="state.hasEpochList"
@@ -126,8 +81,12 @@
12681
translateConcept,
12782
multiselectResetClasslist,
12883
} from '@/helpers/helpers.js';
84+
import CommonEraDropdown from './epoch/CommonEraDropdown.vue';
12985
13086
export default {
87+
components: {
88+
CommonEraDropdown,
89+
},
13190
props: {
13291
name: {
13392
type: String,
@@ -151,6 +110,11 @@
151110
disabled: {
152111
type: Boolean,
153112
},
113+
metadata: {
114+
type: Object,
115+
required: false,
116+
default: _ => new Object(),
117+
},
154118
},
155119
emits: ['change'],
156120
setup(props, context) {
@@ -200,14 +164,16 @@
200164
});
201165
};
202166
const setLabel = (field, value) => {
167+
console.log("setLabel:", field, value);
203168
v[field].handleChange(value);
204169
};
205170
const handleEpochChange = option => {
206171
v.epoch.handleChange(option);
207172
};
208173
209174
// DATA
210-
const timeLabels = ['BC', 'AD'];
175+
176+
211177
const {
212178
handleInput: his,
213179
value: vs,
@@ -328,17 +294,22 @@
328294
}
329295
});
330296
297+
const epochFormat = computed(_ => {
298+
// Default to 'bcad' as it was used before.
299+
return props.metadata?.epoch_format ?? 'bcad';
300+
});
301+
331302
// RETURN
332303
return {
333304
t,
334305
// HELPERS
306+
epochFormat,
335307
translateConcept,
336308
multiselectResetClasslist,
337309
// LOCAL
338310
resetFieldState,
339311
undirtyField,
340312
setLabel,
341-
timeLabels,
342313
handleEpochChange,
343314
// STATE
344315
state,
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<template>
2+
<button
3+
type="button"
4+
class="btn btn-outline-secondary dropdown-toggle"
5+
:disabled="disabled"
6+
data-bs-toggle="dropdown"
7+
aria-haspopup="true"
8+
aria-expanded="false"
9+
>
10+
{{ modelValue }}
11+
</button>
12+
<ul
13+
uib-dropdown-menu
14+
class="dropdown-menu"
15+
>
16+
<a
17+
v-for="(label, i) in timeLabels"
18+
:key="i"
19+
class="dropdown-item"
20+
href="#"
21+
@click.prevent="context.emit('update:modelValue', label)"
22+
>
23+
{{ label }}
24+
</a>
25+
</ul>
26+
</template>
27+
28+
<script>
29+
import { computed } from 'vue';
30+
31+
import { getLabelsOf } from '@/helpers/attributes/epoch';
32+
33+
export default {
34+
props: {
35+
format: {
36+
type: String,
37+
required: true,
38+
},
39+
modelValue: {
40+
type: String,
41+
required: true,
42+
},
43+
},
44+
emits: ['update:modelValue'],
45+
setup(props, context) {
46+
const timeLabels = computed(_ => getLabelsOf(props.format));
47+
48+
return {
49+
context,
50+
timeLabels
51+
}
52+
}
53+
};
54+
</script>
55+
56+
<style lang='scss' scoped></style>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<template>
2+
<!-- In epoch we can decide if we use BC/AD or CE/BCE -->
3+
<div class="epoch-attribute-template">
4+
<label
5+
:title="t('global.attribute-template.epoch-format')"
6+
class="form-label text-truncate"
7+
>
8+
{{ t('global.attribute-template.epoch-format') }}
9+
</label>
10+
<div class="col">
11+
<select
12+
v-model="epochFormat"
13+
class="form-select"
14+
style="min-width: max-content;"
15+
>
16+
<option
17+
v-for="option in getEpochTemplateOptions()"
18+
:value="option.key"
19+
>{{ option.templateLabel }}</option>
20+
</select>
21+
</div>
22+
</div>
23+
</template>
24+
25+
<script>
26+
import {
27+
computed,
28+
} from 'vue';
29+
import { useI18n } from 'vue-i18n';
30+
31+
import {
32+
defaultEpochFormat,
33+
getEpochTemplateOptions,
34+
} from '@/helpers/attributes/epoch.js';
35+
36+
export default {
37+
props: {
38+
modelValue: {
39+
type: Object,
40+
required: true,
41+
},
42+
},
43+
emits: ['update:modelValue'],
44+
setup(props, context) {
45+
const t = useI18n().t;
46+
47+
// FUNCTIONS
48+
const updateModelValue = (updates) => {
49+
context.emit('update:modelValue', {
50+
...props.modelValue,
51+
...updates,
52+
});
53+
};
54+
55+
// DATA
56+
const epochFormat = computed({
57+
get: _ => props.modelValue?.metadata?.epoch_format ?? defaultEpochFormat,
58+
set: value => {
59+
updateModelValue({
60+
metadata: {
61+
...props.modelValue?.metadata,
62+
epoch_format: value,
63+
},
64+
});
65+
},
66+
});
67+
68+
// RETURN
69+
return {
70+
t,
71+
epochFormat,
72+
getEpochTemplateOptions
73+
};
74+
},
75+
};
76+
</script>
77+
78+
<style lang='scss' scoped></style>

0 commit comments

Comments
 (0)