-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull standard-template-service from plugins and pass templates in
- Loading branch information
Showing
10 changed files
with
84 additions
and
8 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-gelinkt-notuleren': patch | ||
--- | ||
|
||
Pass standard templates into standard template plugin instead of it loading them itself |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
export { default } from '@lblod/ember-rdfa-editor-lblod-plugins/models/template'; | ||
import Model, { attr } from '@ember-data/model'; | ||
export default class TemplateModel extends Model { | ||
@attr title; | ||
@attr('string-set', { defaultValue: () => [] }) matches; | ||
@attr body; | ||
@attr('string-set', { defaultValue: () => [] }) contexts; | ||
@attr('string-set', { defaultValue: () => [] }) disabledInContexts; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Service, { inject as service } from '@ember/service'; | ||
import { task, waitForProperty } from 'ember-concurrency'; | ||
import { tracked } from '@glimmer/tracking'; | ||
|
||
const BLACKLISTED_TEMPLATES = new Set(['Citeeropschrift']); | ||
|
||
export default class StandardTemplateService extends Service { | ||
@service store; | ||
@tracked templates; | ||
|
||
constructor(...args) { | ||
super(...args); | ||
this.loadTemplates().catch((err) => | ||
console.error('Error loading standard templates', err), | ||
); | ||
} | ||
|
||
fetchTemplates = task(async () => { | ||
await waitForProperty(this, 'templates'); | ||
return this.templates; | ||
}); | ||
|
||
async loadTemplates() { | ||
const templates = await this.store.query('template', { | ||
fields: { templates: 'title,contexts,matches,disabled-in-contexts' }, | ||
}); | ||
this.templates = templates.filter( | ||
(template) => !BLACKLISTED_TEMPLATES.has(template.title), | ||
); | ||
} | ||
|
||
/** | ||
Filter the valid templates for a context. | ||
@method templatesForContext | ||
@param {Array} Array of templates | ||
@param {Array} The path of rdfaContext objects from the root till the current context | ||
@return {Array} Array of templates (filtered) | ||
@private | ||
*/ | ||
templatesForContext(templates, rdfaTypes) { | ||
const isMatchingForContext = (template) => { | ||
return ( | ||
rdfaTypes.filter((e) => template.get('contexts').includes(e)).length > | ||
0 && | ||
rdfaTypes.filter((e) => template.get('disabledInContexts').includes(e)) | ||
.length === 0 | ||
); | ||
}; | ||
return templates.filter(isMatchingForContext); | ||
} | ||
} |
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