-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor] GH-5 Move ViewDescr here, add aldkg ns
- Loading branch information
Showing
11 changed files
with
470 additions
and
124 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
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,28 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021 Agentlab and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the GNU General Public License v. 3.0 which is available at | ||
* https://www.gnu.org/licenses/gpl-3.0.html. | ||
* | ||
* SPDX-License-Identifier: GPL-3.0-only | ||
********************************************************************************/ | ||
export const viewDescrCollConstr = { | ||
'@id': 'rm:Views_Coll', | ||
entConstrs: [ | ||
{ | ||
'@id': 'rm:Views_EntConstr0', | ||
schema: 'rm:ViewShape', | ||
}, | ||
], | ||
}; | ||
|
||
export const viewKindCollConstr = { | ||
'@id': 'aldkg:ViewKinds_Coll', | ||
entConstrs: [ | ||
{ | ||
'@id': 'aldkg:ViewKinds_EntConstr0', | ||
schema: 'aldkg:ViewKindShape', | ||
}, | ||
], | ||
}; |
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,88 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2020 Agentlab and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the GNU General Public License v. 3.0 which is available at | ||
* https://www.gnu.org/licenses/gpl-3.0.html. | ||
* | ||
* SPDX-License-Identifier: GPL-3.0-only | ||
********************************************************************************/ | ||
import { reaction } from 'mobx'; | ||
import { getParent, getRoot, IAnyModelType, IAnyStateTreeNode, SnapshotIn, types } from 'mobx-state-tree'; | ||
|
||
import { arrDiff, CollConstr, JsObject } from '@agentlab/sparql-jsld-client'; | ||
|
||
export const ViewElement = types.model('ViewElement', { | ||
'@id': types.maybe(types.string), // JSON-LD object id of a view | ||
'@type': types.maybe(types.string), // JSON-LD class id of a View | ||
title: types.maybe(types.string), | ||
description: types.maybe(types.string), | ||
viewKind: types.maybe(types.string), | ||
|
||
type: types.string, | ||
scope: types.maybe(types.string), | ||
resultsScope: types.maybe(types.string), | ||
options: types.maybe(types.frozen<JsObject>()), | ||
|
||
// Container-specific (e.g. Layout, type: 'xxxLayout') | ||
elements: types.maybe(types.array(types.late((): IAnyModelType => ViewElement))), | ||
}); | ||
|
||
/** | ||
* View Description, which could be persisted in DB | ||
*/ | ||
export const ViewDescr = types | ||
.model('ViewDescr', { | ||
'@id': types.identifier, // JSON-LD object id of a view | ||
'@type': types.string, // JSON-LD class id of a View | ||
viewKind: types.maybe(types.string), | ||
|
||
title: types.maybe(types.string), // mandatory title | ||
description: types.maybe(types.string), | ||
|
||
type: types.string, | ||
scope: types.maybe(types.string), | ||
resultsScope: types.maybe(types.string), | ||
options: types.maybe(types.frozen<JsObject>()), | ||
|
||
// Container-specific (e.g. Layout, type: 'xxxLayout') | ||
elements: types.array(ViewElement), | ||
|
||
collsConstrs: types.array(CollConstr), // former 'queries' | ||
}) | ||
.actions((self) => { | ||
const rep: IAnyStateTreeNode = getRoot(self); | ||
const coll: IAnyStateTreeNode = getParent(self, 2); | ||
let disp: any; | ||
return { | ||
afterAttach() { | ||
console.log('ViewDescr afterAttach, @id=', self['@id']); | ||
if (coll.resolveCollConstrs) { | ||
disp = reaction( | ||
() => self.collsConstrs, | ||
(newArr: any[], oldArr: any[]) => { | ||
console.log('ViewDescr reaction, add coll ref, @id=', self['@id']); | ||
const { deleted, added } = arrDiff(newArr, oldArr); | ||
console.log('ViewDescr reaction, add coll ref, {deleted,added}=', { deleted, added }); | ||
deleted.forEach((e: any) => rep.colls.delete(e['@id'])); | ||
added.forEach((e: any) => rep.addCollByConstrRef(e)); | ||
}, | ||
{ fireImmediately: true }, | ||
); | ||
} | ||
}, | ||
beforeDetach() { | ||
console.log('ViewDescr beforeDetach, @id=', self['@id']); | ||
if (coll.resolveCollConstrs) { | ||
if (disp) disp(); | ||
self.collsConstrs.forEach((e) => rep.colls.delete(e['@id'])); | ||
} | ||
}, | ||
setCollConstrs(collsConstrs: any[]) { | ||
const ccso = collsConstrs.map((cc) => CollConstr.create(cc)); | ||
self.collsConstrs.push(...ccso); | ||
}, | ||
}; | ||
}); | ||
|
||
export type IViewDescrSnapshotIn = SnapshotIn<typeof ViewDescr>; |
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,62 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2020 Agentlab and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the GNU General Public License v. 3.0 which is available at | ||
* https://www.gnu.org/licenses/gpl-3.0.html. | ||
* | ||
* SPDX-License-Identifier: GPL-3.0-only | ||
********************************************************************************/ | ||
import { JSONSchema6forRdf } from '@agentlab/sparql-jsld-client'; | ||
|
||
export const ViewShapeSchema: JSONSchema6forRdf = { | ||
$schema: 'http://json-schema.org/draft-07/schema#', | ||
'@id': 'rm:ViewShape', | ||
'@type': 'sh:NodeShape', | ||
title: 'View Shape', | ||
description: 'Artifact Shape', | ||
targetClass: 'aldkg:ViewDescr', | ||
type: 'object', | ||
'@context': { | ||
'@type': 'rdf:type', | ||
}, | ||
properties: { | ||
'@id': { | ||
title: 'URI', | ||
type: 'string', | ||
format: 'iri', | ||
}, | ||
'@type': { | ||
title: 'Тип', | ||
type: 'string', | ||
format: 'iri', | ||
}, | ||
}, | ||
required: ['@id', '@type'], | ||
}; | ||
|
||
export const ViewKindShapeSchema: JSONSchema6forRdf = { | ||
$schema: 'http://json-schema.org/draft-07/schema#', | ||
'@id': 'rm:ViewShape', | ||
'@type': 'sh:NodeShape', | ||
title: 'View Shape', | ||
description: 'Artifact Shape', | ||
targetClass: 'aldkg:ViewDescr', | ||
type: 'object', | ||
'@context': { | ||
'@type': 'rdf:type', | ||
}, | ||
properties: { | ||
'@id': { | ||
title: 'URI', | ||
type: 'string', | ||
format: 'iri', | ||
}, | ||
'@type': { | ||
title: 'Тип', | ||
type: 'string', | ||
format: 'iri', | ||
}, | ||
}, | ||
required: ['@id', '@type'], | ||
}; |
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
Oops, something went wrong.