2021-12-19 09:56:22 -08:00
|
|
|
/* eslint-disable no-unused-vars */
|
2021-12-03 16:43:50 -08:00
|
|
|
/* eslint-disable class-methods-use-this */
|
2021-07-16 11:41:58 -03:00
|
|
|
/*
|
2021-12-25 14:39:34 -08:00
|
|
|
* Copyright [2021] [wisemapping]
|
2021-07-16 11:41:58 -03:00
|
|
|
*
|
|
|
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
|
|
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
|
|
|
* "powered by wisemapping" text requirement on every single page;
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the license at
|
|
|
|
*
|
|
|
|
* http://www.wisemapping.org/license
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2021-12-19 00:44:08 -08:00
|
|
|
import { $assert } from '@wisemapping/core-js';
|
2022-01-02 14:01:50 -08:00
|
|
|
import INodeModel, { NodeModelType as NodeType } from './INodeModel';
|
2021-12-29 18:35:58 +00:00
|
|
|
import RelationshipModel from './RelationshipModel';
|
2021-07-16 11:41:58 -03:00
|
|
|
|
2021-12-29 18:35:58 +00:00
|
|
|
abstract class IMindmap {
|
2022-01-02 14:01:50 -08:00
|
|
|
getCentralTopic(): INodeModel {
|
2021-10-04 17:05:34 -07:00
|
|
|
return this.getBranches()[0];
|
2021-12-03 10:58:25 -08:00
|
|
|
}
|
2021-10-04 17:05:34 -07:00
|
|
|
|
2021-12-29 18:35:58 +00:00
|
|
|
abstract getDescription(): string;
|
2021-10-04 17:05:34 -07:00
|
|
|
|
2022-01-02 14:01:50 -08:00
|
|
|
abstract setDescription(value: string): void;
|
2021-10-04 17:05:34 -07:00
|
|
|
|
2021-12-29 18:35:58 +00:00
|
|
|
abstract getId(): string
|
2021-10-04 17:05:34 -07:00
|
|
|
|
2022-01-02 14:01:50 -08:00
|
|
|
abstract setId(id: string): void;
|
2021-10-04 17:05:34 -07:00
|
|
|
|
2021-12-29 18:35:58 +00:00
|
|
|
abstract getVersion(): string;
|
2021-10-04 17:05:34 -07:00
|
|
|
|
2021-12-29 18:35:58 +00:00
|
|
|
abstract setVersion(version: string): void;
|
2021-10-04 17:05:34 -07:00
|
|
|
|
2022-01-02 14:01:50 -08:00
|
|
|
abstract addBranch(nodeModel: INodeModel): void;
|
2021-10-04 17:05:34 -07:00
|
|
|
|
2022-01-02 14:01:50 -08:00
|
|
|
abstract getBranches(): Array<INodeModel>;
|
2021-10-04 17:05:34 -07:00
|
|
|
|
2022-01-02 14:01:50 -08:00
|
|
|
abstract removeBranch(node: INodeModel): void;
|
2021-10-04 17:05:34 -07:00
|
|
|
|
2021-12-29 18:35:58 +00:00
|
|
|
abstract getRelationships(): Array<RelationshipModel>;
|
2021-10-04 17:05:34 -07:00
|
|
|
|
2022-01-02 14:01:50 -08:00
|
|
|
connect(parent: INodeModel, child: INodeModel): void {
|
2021-10-04 17:05:34 -07:00
|
|
|
// Child already has a parent ?
|
|
|
|
$assert(!child.getParent(), 'Child model seems to be already connected');
|
2021-07-16 11:41:58 -03:00
|
|
|
|
2021-10-04 17:05:34 -07:00
|
|
|
// Connect node...
|
|
|
|
parent.append(child);
|
2021-07-16 11:41:58 -03:00
|
|
|
|
2021-10-04 17:05:34 -07:00
|
|
|
// Remove from the branch ...
|
|
|
|
this.removeBranch(child);
|
2021-12-03 10:58:25 -08:00
|
|
|
}
|
2021-07-16 11:41:58 -03:00
|
|
|
|
2021-10-04 17:05:34 -07:00
|
|
|
/**
|
2021-07-16 11:41:58 -03:00
|
|
|
* @param child
|
|
|
|
* @throws will throw an error if child is null or undefined
|
|
|
|
* @throws will throw an error if child's parent cannot be found
|
|
|
|
*/
|
2022-01-02 14:01:50 -08:00
|
|
|
disconnect(child: INodeModel): void {
|
2021-10-04 17:05:34 -07:00
|
|
|
const parent = child.getParent();
|
|
|
|
$assert(child, 'Child can not be null.');
|
|
|
|
$assert(parent, 'Child model seems to be already connected');
|
|
|
|
|
|
|
|
parent.removeChild(child);
|
|
|
|
this.addBranch(child);
|
2021-12-03 10:58:25 -08:00
|
|
|
}
|
2021-10-04 17:05:34 -07:00
|
|
|
|
2022-01-02 14:01:50 -08:00
|
|
|
abstract hasAlreadyAdded(node: INodeModel): boolean;
|
2021-10-04 17:05:34 -07:00
|
|
|
|
2022-01-03 07:12:12 -08:00
|
|
|
abstract createNode(type: NodeType, id: number): INodeModel
|
2021-10-04 17:05:34 -07:00
|
|
|
|
2022-01-24 11:51:20 -08:00
|
|
|
abstract createRelationship(fromNodeId: number, toNodeId: number): void;
|
2021-10-04 17:05:34 -07:00
|
|
|
|
2021-12-29 18:35:58 +00:00
|
|
|
abstract addRelationship(rel: RelationshipModel): void;
|
2021-10-04 17:05:34 -07:00
|
|
|
|
2022-01-02 14:01:50 -08:00
|
|
|
abstract deleteRelationship(relationship: RelationshipModel): void;
|
2021-10-04 17:05:34 -07:00
|
|
|
|
|
|
|
/** */
|
|
|
|
inspect() {
|
|
|
|
let result = '';
|
|
|
|
result = '{ ';
|
|
|
|
|
|
|
|
const branches = this.getBranches();
|
2021-12-19 09:56:22 -08:00
|
|
|
result = `${result} , version:${this.getVersion()}`;
|
2021-10-04 17:05:34 -07:00
|
|
|
result = `${result} , [`;
|
|
|
|
|
|
|
|
for (let i = 0; i < branches.length; i++) {
|
|
|
|
const node = branches[i];
|
2021-12-03 16:43:50 -08:00
|
|
|
if (i !== 0) {
|
2021-10-04 17:05:34 -07:00
|
|
|
result = `${result},\n `;
|
|
|
|
}
|
|
|
|
result = `${result}(${i}) =>${node.inspect()}`;
|
|
|
|
}
|
|
|
|
result = `${result}]`;
|
|
|
|
|
|
|
|
result = `${result} } `;
|
|
|
|
return result;
|
2021-12-03 10:58:25 -08:00
|
|
|
}
|
2021-10-04 17:05:34 -07:00
|
|
|
|
|
|
|
/**
|
2021-07-16 11:41:58 -03:00
|
|
|
* @param target
|
|
|
|
*/
|
2021-10-04 17:05:34 -07:00
|
|
|
copyTo(target) {
|
|
|
|
const source = this;
|
|
|
|
const version = source.getVersion();
|
|
|
|
target.setVersion(version);
|
|
|
|
|
|
|
|
const desc = this.getDescription();
|
|
|
|
target.setDescription(desc);
|
|
|
|
|
|
|
|
// Then the rest of the branches ...
|
|
|
|
const sbranchs = source.getBranches();
|
2021-12-05 08:14:15 -08:00
|
|
|
sbranchs.forEach((snode) => {
|
2021-10-04 17:05:34 -07:00
|
|
|
const tnode = target.createNode(snode.getType(), snode.getId());
|
|
|
|
snode.copyTo(tnode);
|
|
|
|
target.addBranch(tnode);
|
|
|
|
});
|
2021-12-03 10:58:25 -08:00
|
|
|
}
|
|
|
|
}
|
2021-07-16 11:41:58 -03:00
|
|
|
|
2021-10-04 17:05:34 -07:00
|
|
|
export default IMindmap;
|