-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #301 from lblod/feat/regenerate-variable-uris
Feat/regenerate variable uris
- Loading branch information
Showing
7 changed files
with
96 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters