2018-01-22 21:30:53 +03:00
|
|
|
import { action, observable } from 'mobx';
|
2017-10-12 00:01:37 +03:00
|
|
|
|
|
|
|
import { OpenAPIExternalDocumentation, OpenAPITag } from '../../types';
|
2018-07-17 15:21:03 +03:00
|
|
|
import { safeSlugify } from '../../utils';
|
2018-06-20 19:29:46 +03:00
|
|
|
import { MarkdownHeading } from '../MarkdownRenderer';
|
2017-10-12 00:01:37 +03:00
|
|
|
import { ContentItemModel } from '../MenuBuilder';
|
|
|
|
import { IMenuItem, MenuItemGroupType } from '../MenuStore';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Operations Group model ready to be used by components
|
|
|
|
*/
|
|
|
|
export class GroupModel implements IMenuItem {
|
|
|
|
//#region IMenuItem fields
|
|
|
|
id: string;
|
|
|
|
absoluteIdx?: number;
|
|
|
|
name: string;
|
|
|
|
description?: string;
|
|
|
|
type: MenuItemGroupType;
|
|
|
|
|
2018-01-22 21:30:53 +03:00
|
|
|
items: ContentItemModel[] = [];
|
2017-10-12 00:01:37 +03:00
|
|
|
parent?: GroupModel;
|
|
|
|
externalDocs?: OpenAPIExternalDocumentation;
|
|
|
|
|
2018-08-18 16:23:33 +03:00
|
|
|
@observable
|
|
|
|
active: boolean = false;
|
|
|
|
@observable
|
|
|
|
expanded: boolean = false;
|
2017-10-12 00:01:37 +03:00
|
|
|
|
|
|
|
depth: number;
|
2018-08-08 11:37:48 +03:00
|
|
|
level: number;
|
2017-10-12 00:01:37 +03:00
|
|
|
//#endregion
|
|
|
|
|
2018-06-20 19:29:46 +03:00
|
|
|
constructor(
|
|
|
|
type: MenuItemGroupType,
|
|
|
|
tagOrGroup: OpenAPITag | MarkdownHeading,
|
|
|
|
parent?: GroupModel,
|
|
|
|
) {
|
|
|
|
// markdown headings already have ids calculated as they are needed for heading anchors
|
2018-07-17 15:21:03 +03:00
|
|
|
this.id = (tagOrGroup as MarkdownHeading).id || type + '/' + safeSlugify(tagOrGroup.name);
|
2017-10-12 00:01:37 +03:00
|
|
|
this.type = type;
|
|
|
|
this.name = tagOrGroup['x-displayName'] || tagOrGroup.name;
|
2018-08-08 11:37:48 +03:00
|
|
|
this.level = (tagOrGroup as MarkdownHeading).level || 1;
|
2017-10-12 00:01:37 +03:00
|
|
|
this.description = tagOrGroup.description || '';
|
|
|
|
this.parent = parent;
|
2018-06-20 19:29:46 +03:00
|
|
|
this.externalDocs = (tagOrGroup as OpenAPITag).externalDocs;
|
2017-10-12 00:01:37 +03:00
|
|
|
|
|
|
|
// groups are active (expanded) by default
|
|
|
|
if (this.type === 'group') {
|
2018-07-31 15:53:52 +03:00
|
|
|
this.expanded = true;
|
2017-10-12 00:01:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
activate() {
|
|
|
|
this.active = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
2018-07-31 15:53:52 +03:00
|
|
|
expand() {
|
|
|
|
if (this.parent) {
|
|
|
|
this.parent.expand();
|
|
|
|
}
|
|
|
|
this.expanded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
collapse() {
|
|
|
|
// disallow collapsing groups
|
2018-01-22 21:30:53 +03:00
|
|
|
if (this.type === 'group') {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-31 15:53:52 +03:00
|
|
|
this.expanded = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
deactivate() {
|
2017-10-12 00:01:37 +03:00
|
|
|
this.active = false;
|
|
|
|
}
|
|
|
|
}
|