-
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 #302 from lblod/utils/imported-resources-fixes
Quickly connect all articles in a snippet to an imported resource
- Loading branch information
Showing
5 changed files
with
108 additions
and
0 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 utility button to quickly connect all articles in a snippet to an imported resource |
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,29 @@ | ||
<AuCard | ||
@flex={{true}} | ||
@divided={{true}} | ||
@isOpenInitially={{true}} | ||
@expandable={{true}} | ||
@shadow={{true}} | ||
@size='small' | ||
as |c| | ||
> | ||
<c.header> | ||
{{!-- template-lint-disable no-bare-strings --}} | ||
<AuHeading @level='3' @skin='6'> | ||
Connect articles to imported resource | ||
</AuHeading> | ||
</c.header> | ||
<c.content> | ||
<AuButton | ||
@disabled={{this.docIsConnected}} | ||
{{on 'click' this.connect}} | ||
> | ||
{{!-- template-lint-disable no-bare-strings --}} | ||
{{#if this.docIsConnected}} | ||
Connected | ||
{{else}} | ||
Connect | ||
{{/if}} | ||
</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,66 @@ | ||
import Component from '@glimmer/component'; | ||
import { action } from '@ember/object'; | ||
import { addProperty } from '@lblod/ember-rdfa-editor/commands/rdfa-commands/add-property'; | ||
import { sayDataFactory } from '@lblod/ember-rdfa-editor/core/say-data-factory'; | ||
import { IMPORTED_RESOURCES_ATTR } from '@lblod/ember-rdfa-editor/plugins/imported-resources'; | ||
|
||
export default class ConnectArticlesToImportedResourceComponent extends Component { | ||
get controller() { | ||
return this.args.controller; | ||
} | ||
|
||
get importedResource() { | ||
return this.args.importedResource; | ||
} | ||
|
||
get nonConnectedArticleURIs() { | ||
const doc = this.controller.mainEditorState.doc; | ||
const articleURIs = new Set(); | ||
doc.descendants((node) => { | ||
if ( | ||
node.type === this.controller.schema.nodes.structure && | ||
node.attrs.structureType === 'article' && | ||
!this.isConnected(node) | ||
) { | ||
articleURIs.add(node.attrs.subject); | ||
} | ||
}); | ||
return articleURIs; | ||
} | ||
|
||
get docIsConnected() { | ||
return this.nonConnectedArticleURIs.size === 0; | ||
} | ||
|
||
@action | ||
connect() { | ||
const articleURIs = this.nonConnectedArticleURIs; | ||
for (const uri of articleURIs) { | ||
this.controller.doCommand( | ||
addProperty({ | ||
resource: this.importedResource, | ||
property: { | ||
predicate: 'http://data.europa.eu/eli/ontology#has_part', | ||
object: sayDataFactory.resourceNode(uri), | ||
}, | ||
isNewImportedResource: !this.documentImportedResources.includes( | ||
this.importedResource, | ||
), | ||
}), | ||
); | ||
} | ||
} | ||
|
||
get documentImportedResources() { | ||
return this.controller.getDocumentAttribute(IMPORTED_RESOURCES_ATTR) ?? []; | ||
} | ||
|
||
isConnected(articleNode) { | ||
return Boolean( | ||
(articleNode.attrs.backlinks ?? []).some( | ||
(backlink) => | ||
backlink.predicate == 'http://data.europa.eu/eli/ontology#has_part', | ||
), | ||
); | ||
} | ||
} |
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