Skip to content

Commit

Permalink
Merge pull request #301 from lblod/feat/regenerate-variable-uris
Browse files Browse the repository at this point in the history
Feat/regenerate variable uris
  • Loading branch information
elpoelma authored Nov 25, 2024
2 parents 8ea3c40 + afaaee0 commit 3dd3654
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/warm-months-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"frontend-reglementaire-bijlage": minor
---

Add a card to regenerate variable uris
22 changes: 22 additions & 0 deletions app/components/regenerate-variable-uris.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<AuCard
@flex={{true}}
@divided={{true}}
@isOpenInitially={{true}}
@expandable={{true}}
@shadow={{true}}
@size='small'
as |c|
>
<c.header>
<AuHeading @level='3' @skin='6'>
{{t 'regenerate-variable-uris.modal-title'}}
</AuHeading>
</c.header>
<c.content>
<AuButton
{{on 'click' this.regenerate}}
>
{{t 'regenerate-variable-uris.button'}}
</AuButton>
</c.content>
</AuCard>
52 changes: 52 additions & 0 deletions app/components/regenerate-variable-uris.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { getOutgoingTriple } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/namespace';
import { EXT } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
import { v4 as uuidv4 } from 'uuid';
import { sayDataFactory } from '@lblod/ember-rdfa-editor/core/say-data-factory';

const VARIABLE_TYPES = [
'address',
'date',
'text_variable',
'oslo_location',
'person_variable',
'autofilled_variable',
'number',
'codelist',
];
export default class RegenerateVariableUrisComponent extends Component {
get controller() {
return this.args.controller;
}

@action
regenerate() {
const doc = this.controller.mainEditorState.doc;
const nodesReversed = [];
doc.descendants((node, pos) => {
if (VARIABLE_TYPES.includes(node.type.name)) {
nodesReversed.unshift({ node, pos });
}
});
for (let { node, pos } of nodesReversed) {
this.recreateUris(node, pos);
}
}
recreateUris(node, pos) {
const newAttrs = { ...node.attrs };
if (newAttrs.subject) {
newAttrs.subject = `http://data.lblod.info/mappings/--ref-uuid4-${uuidv4()}`;
}
const instanceTriple = getOutgoingTriple(newAttrs, EXT('instance'));
if (instanceTriple) {
let recreatedUri = `http://data.lblod.info/variables/--ref-uuid4-${uuidv4()}`;
instanceTriple.object = sayDataFactory.namedNode(recreatedUri);
}
this.controller.withTransaction((tr) => {
tr.setNodeAttribute(pos, 'subject', newAttrs.subject);
tr.setNodeAttribute(pos, 'properties', newAttrs.properties);
return tr;
});
}
}
1 change: 1 addition & 0 deletions app/templates/snippet-management/edit/edit-snippet.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
@options={{this.config.structures}}
/>
</Sidebar.Collapsible>
<RegenerateVariableUris @controller={{this.editor}} />
<this.StructureControlCard @controller={{this.editor}} />
<MandateeTablePlugin::Configure
@controller={{this.editor}}
Expand Down
3 changes: 3 additions & 0 deletions app/templates/template-management/edit.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
/>
</Sidebar.Collapsible>
{{/unless}}
<RegenerateVariableUris @controller={{this.editor}} />
<Plugins::Link::LinkEditor @controller={{this.editor}} />
<this.RdfaEditor
@node={{this.activeNode}}
Expand All @@ -202,6 +203,7 @@
/>
<this.DebugInfo @node={{this.activeNode}} />
{{/if}}

<this.StructureControl @controller={{this.editor}} />
<MandateeTablePlugin::Configure
@controller={{this.editor}}
Expand All @@ -228,6 +230,7 @@
/>
<VariablePlugin::Autofilled::Edit @controller={{this.editor}} />
<TemplateCommentsPlugin::EditCard @controller={{this.editor}} />

{{! VariablePlugin::TemplateVariableCard is not added on purpose
as an RB-document creator should not be able to set a "default" codelist option.}}
</Sidebar>
Expand Down
8 changes: 6 additions & 2 deletions translations/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ codelist:
options: "Options"
id: Id
types:
singleSelect: 'Single select'
multiSelect: 'Multi select'
singleSelect: "Single select"
multiSelect: "Multi select"
options:
label: Label
label-explanation: Optional shorter description
Expand Down Expand Up @@ -216,3 +216,7 @@ editor:

search-form:
aria-label: Search

regenerate-variable-uris:
modal-title: Regenerate variable URIs
button: Regenerate
10 changes: 7 additions & 3 deletions translations/nl-BE.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ codelist:
options: "Items"
id: Id
types:
singleSelect: 'Single select'
multiSelect: 'Multi select'
singleSelect: "Single select"
multiSelect: "Multi select"
options:
label: Label
label-explanation: Optionele kortere weergave
Expand Down Expand Up @@ -102,7 +102,7 @@ template-management:
save: Opslaan
cancel: Terug
remove-modal:
title: Weet u zeker dat u dit sjabloon wilt verwijderen?
title: Weet u zeker dat u dit sjabloon wilt verwijderen?
remove: Sjabloon verwijderen
cancel: Terug
template-edit:
Expand Down Expand Up @@ -210,3 +210,7 @@ editor:

search-form:
aria-label: Zoek

regenerate-variable-uris:
modal-title: Variabele URI's opnieuw genereren
button: Regenereer

0 comments on commit 3dd3654

Please sign in to comment.