Skip to content
This repository has been archived by the owner on Oct 20, 2021. It is now read-only.

Commit

Permalink
feat: global markdown template pages
Browse files Browse the repository at this point in the history
  • Loading branch information
ytvnr committed Feb 24, 2021
1 parent ef0cf58 commit 6e55f52
Show file tree
Hide file tree
Showing 17 changed files with 240 additions and 57 deletions.
10 changes: 10 additions & 0 deletions src/assets/logo_markdown_template.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/assets/logo_markdown_template_old2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions src/assets/logo_markdown_templateold.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 15 additions & 2 deletions src/components/documentation/documentation-management.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
*/

import NotificationService from '../../services/notification.service';
import DocumentationService, {DocumentationQuery, FolderSituation, SystemFolderName} from '../../services/documentation.service';
import DocumentationService, {
DocumentationQuery,
FolderSituation,
PageType,
SystemFolderName
} from '../../services/documentation.service';
import {StateService} from '@uirouter/core';
import _ = require('lodash');
import {IScope} from 'angular';
Expand Down Expand Up @@ -53,12 +58,20 @@ const DocumentationManagementComponent: ng.IComponentOptions = {
this.systemFoldersById = _.keyBy(this.systemFolders, 'id');

this.currentFolder = this.getFolder(this.rootDir);
this.supportedTypes = DocumentationService.supportedTypes(this.getFolderSituation(this.rootDir));
this.supportedTypes = DocumentationService
.supportedTypes(this.getFolderSituation(this.rootDir))
.filter(type => !this.apiId || type !== PageType.MARKDOWN_TEMPLATE);
this.breadcrumb = this.generateBreadcrumb();
$scope.renameFolder = false;
$scope.translateFolder = false;
};

this.isFolder = (type: string): boolean => PageType.FOLDER === type;
this.isLink = (type: string): boolean => PageType.LINK === type;
this.isSwagger = (type: string): boolean => PageType.SWAGGER === type;
this.isMarkdown = (type: string): boolean => PageType.MARKDOWN === type;
this.isMarkdownTemplate = (type: string): boolean => PageType.MARKDOWN_TEMPLATE === type;

this.getFolderSituation = (folderId: string) => {
if (!folderId) {
return FolderSituation.ROOT;
Expand Down
18 changes: 13 additions & 5 deletions src/components/documentation/documentation-management.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ <h2>
</tbody>
</table>
</md-table-container>

<div style="text-align: right">
<md-button permission permission-only="['environment-documentation-u', 'api-documentation-u']"
type="button"
Expand Down Expand Up @@ -219,15 +219,23 @@ <h2>
</ng-md-icon>
</td>
<td md-cell width="48px">
<ng-md-icon ng-if="!page.published && page.type !== 'LINK'" icon="cloud_queue" ng-click="$ctrl.togglePublish(page)"
<ng-md-icon ng-if="!page.published && !$ctrl.isLink(page.type)"
icon="{{$ctrl.isMarkdownTemplate(page.type) ? 'check_box_outline_blank' : 'cloud_queue'}}"
ng-click="$ctrl.togglePublish(page)"
style="font-size: 24px; height: 24px;"
permission permission-only="['environment-documentation-u', 'api-documentation-u']">
<md-tooltip md-direction="top" md-visible="false">Publish this page</md-tooltip>
<md-tooltip md-direction="top" md-visible="false">
{{$ctrl.isMarkdownTemplate(page.type) ? 'Make template available' : 'Publish this page'}}
</md-tooltip>
</ng-md-icon>
<ng-md-icon ng-if="page.published && page.type !== 'LINK'" icon="cloud_done" ng-click="$ctrl.togglePublish(page)"
<ng-md-icon ng-if="page.published && !$ctrl.isLink(page.type)"
icon="{{$ctrl.isMarkdownTemplate(page.type) ? 'check_box' : 'cloud_done'}}"
ng-click="$ctrl.togglePublish(page)"
style="font-size: 24px; height: 24px;"
permission permission-only="['environment-documentation-u', 'api-documentation-u']">
<md-tooltip md-direction="top" md-visible="false">Unpublish this page</md-tooltip>
<md-tooltip md-direction="top" md-visible="false">
{{$ctrl.isMarkdownTemplate(page.type) ? 'Make template unavailable' : 'Unpublish this page'}}
</md-tooltip>
</ng-md-icon>
</td>
<td md-cell width="76px" nowrap>
Expand Down
15 changes: 13 additions & 2 deletions src/components/documentation/edit-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
*/

import NotificationService from '../../services/notification.service';
import DocumentationService, { FolderSituation, SystemFolderName } from '../../services/documentation.service';
import DocumentationService, {
FolderSituation,
PageType,
SystemFolderName
} from '../../services/documentation.service';
import { StateService } from '@uirouter/core';
import { IScope } from 'angular';
import UserService from '../../services/user.service';
Expand Down Expand Up @@ -126,6 +130,13 @@ const EditPageComponent: ng.IComponentOptions = {

};

this.isFolder = (): boolean => PageType.FOLDER === this.page.type;
this.isLink = (): boolean => PageType.LINK === this.page.type;
this.isSwagger = (): boolean => PageType.SWAGGER === this.page.type;
this.isMarkdown = (): boolean => PageType.MARKDOWN === this.page.type;
this.isMarkdownTemplate = (): boolean => PageType.MARKDOWN_TEMPLATE === this.page.type;


this.usedAsGeneralConditions = () => {
return this.page.generalConditions;
};
Expand All @@ -143,7 +154,7 @@ const EditPageComponent: ng.IComponentOptions = {
parentId: this.page.id,
configuration: {}
};
if (this.page.type === 'MARKDOWN' || this.page.type === 'SWAGGER') {
if (this.isMarkdown() || this.isSwagger() || this.isMarkdownTemplate()) {
this.currentTranslation.configuration.inheritContent = 'true';
}
};
Expand Down
27 changes: 14 additions & 13 deletions src/components/documentation/edit-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<div>
<md-icon md-svg-src="assets/logo_{{$ctrl.page.type | lowercase}}.svg" style="margin: 0 8px 12px 0;"></md-icon>
<h1>{{$ctrl.page.name}}</h1>
<sup ng-if="('LINK' === $ctrl.page.type && $ctrl.page.configuration.inherit && $ctrl.page.configuration.inherit === 'true')">
<sup ng-if="($ctrl.isLink() && $ctrl.page.configuration.inherit && $ctrl.page.configuration.inherit === 'true')">
<ng-md-icon icon="lock" size="12" style="fill: black;">
<md-tooltip>Inherited</md-tooltip>
</ng-md-icon>
Expand All @@ -35,7 +35,7 @@ <h1>{{$ctrl.page.name}}</h1>
class="md-raised md-primary"
ng-click="$ctrl.toggleRename()"
aria-label="Rename"
ng-if="'LINK' !== $ctrl.page.type || ('LINK' === $ctrl.page.type && (!$ctrl.page.configuration.inherit || $ctrl.page.configuration.inherit === 'false')) ">
ng-if="!$ctrl.isLink() || ($ctrl.isLink() && (!$ctrl.page.configuration.inherit || $ctrl.page.configuration.inherit === 'false')) ">
Rename
</md-button>
<md-button ng-if="$ctrl.page.metadata.edit_url" type="button" style="padding: 0 6px;"
Expand Down Expand Up @@ -69,7 +69,7 @@ <h1>{{$ctrl.page.name}}</h1>
</div>

<!-- LINK-->
<div class="gv-form" ng-if="'LINK' === $ctrl.page.type">
<div class="gv-form" ng-if="$ctrl.isLink()">
<h2></h2>
<div class="gv-form-content" layout="column">
<md-tabs md-dynamic-height md-selected="$ctrl.selectedTab">
Expand Down Expand Up @@ -250,7 +250,7 @@ <h2></h2>
</div>

<!-- SWAGGER or MARKDOWN-->
<div class="gv-form" ng-if="'FOLDER' !== $ctrl.page.type && 'LINK' !== $ctrl.page.type">
<div class="gv-form" ng-if="!$ctrl.isFolder() && !$ctrl.isLink()">
<h2></h2>
<div class="gv-form-content" layout="column">

Expand All @@ -266,7 +266,7 @@ <h2></h2>
<md-tab-body>
<div ng-if="$ctrl.currentTab === 'content'">
<!-- edit SWAGGER inline -->
<div ng-if="'SWAGGER' === $ctrl.page.type" style="display: inline-block; width: 100%;">
<div ng-if="$ctrl.isSwagger()" style="display: inline-block; width: 100%;">
<div layout="row" style="max-height: 900px; overflow: auto;">
<md-input-container class="md-block" flex="50" ng-if="$ctrl.canUpdate">
<textarea
Expand All @@ -283,7 +283,7 @@ <h2></h2>
</div>

<!-- edit MARKDOWN inline -->
<div ng-if="'MARKDOWN' === $ctrl.page.type" style="display: inline-block; width: 100%;">
<div ng-if="$ctrl.isMarkdown() || $ctrl.isMarkdownTemplate()" style="display: inline-block; width: 100%;">
<div class="md-block">
<gv-page-editor-markdown ng-if="$ctrl.canUpdate" page="$ctrl.page" pages-to-link="$ctrl.pagesToLink"></gv-page-editor-markdown>
<gv-page-markdown ng-if="!$ctrl.canUpdate" page="$ctrl.page"></gv-page-markdown>
Expand Down Expand Up @@ -373,7 +373,7 @@ <h4>Select a file to import:</h4>

<div ng-if="$ctrl.currentTranslation.configuration.inheritContent === 'false'">
<!-- edit SWAGGER inline -->
<div ng-if="'SWAGGER' === $ctrl.page.type" style="display: inline-block; width: 100%;">
<div ng-if="$ctrl.isSwagger()" style="display: inline-block; width: 100%;">
<div layout="row" style="max-height: 900px; overflow: auto;">
<md-input-container class="md-block" flex="50" ng-if="$ctrl.canUpdate">
<textarea
Expand All @@ -389,7 +389,7 @@ <h4>Select a file to import:</h4>
</div>

<!-- edit MARKDOWN inline -->
<div ng-if="'MARKDOWN' === $ctrl.page.type" style="display: inline-block; width: 100%;">
<div ng-if="$ctrl.isMarkdown() || $ctrl.isMarkdownTemplate()" style="display: inline-block; width: 100%;">
<md-input-container class="md-block">
<gv-page-editor-markdown ng-if="$ctrl.canUpdate" page="$ctrl.currentTranslation"></gv-page-editor-markdown>
<gv-page-markdown ng-if="!$ctrl.canUpdate" page="$ctrl.currentTranslation"></gv-page-markdown>
Expand All @@ -406,7 +406,7 @@ <h4>Select a file to import:</h4>
<md-tab-label>Configuration</md-tab-label>
<md-tab-body>
<h3>General</h3>
<md-input-container class="md-block">
<md-input-container ng-if="!$ctrl.isMarkdownTemplate()" class="md-block">
<md-checkbox ng-model="$ctrl.page.homepage"
aria-label="set as homepage"
class="md-align-top-left"
Expand All @@ -416,15 +416,16 @@ <h3>General</h3>
</md-input-container>
<md-input-container class="md-block">
<md-checkbox ng-model="$ctrl.page.published"
aria-label="Published"
aria-label="{{!$ctrl.isMarkdownTemplate() ? 'Published' : 'Available'}}"
class="md-align-top-left"
flex
ng-disabled="$ctrl.usedAsGeneralConditions()">
{{($ctrl.usedAsGeneralConditions() ? 'Publish this page (Used as general conditions, publishing actions are disabled)' : 'Publish this page')}}
{{($ctrl.usedAsGeneralConditions() ? 'Publish this page (Used as general conditions, publishing actions are disabled)'
: !$ctrl.isMarkdownTemplate() ? 'Publish this page' : 'Make template available')}}
</md-checkbox>
</md-input-container>
<!-- SWAGGER Configuration -->
<div ng-if="$ctrl.page.type === 'SWAGGER'" layout="column">
<div ng-if="$ctrl.isSwagger()" layout="column">

<div ng-if="$ctrl.shouldShowOpenApiDocFormat">
<h3>OpenAPI documentation viewer: </h3>
Expand Down Expand Up @@ -525,7 +526,7 @@ <h3>Groups Authorizations</h3>
</md-tab>

<!-- Attached resources -->
<md-tab md-on-select="$ctrl.selectTab(5)" ng-if="$ctrl.canUpdate && $ctrl.page.type === 'MARKDOWN'">
<md-tab md-on-select="$ctrl.selectTab(5)" ng-if="$ctrl.canUpdate && $ctrl.isMarkdown()">
<md-tab-label>Attached resources</md-tab-label>
<md-tab-body>
<md-table-container>
Expand Down
53 changes: 51 additions & 2 deletions src/components/documentation/new-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
*/

import NotificationService from '../../services/notification.service';
import DocumentationService, { FolderSituation, SystemFolderName } from '../../services/documentation.service';
import DocumentationService, {
DocumentationQuery,
FolderSituation,
Page,
PageType,
SystemFolderName
} from '../../services/documentation.service';
import { StateService } from '@uirouter/core';
import { IScope } from 'angular';
import _ = require('lodash');
Expand Down Expand Up @@ -60,7 +66,6 @@ const NewPageComponent: ng.IComponentOptions = {
mode: 'javascript'
};


this.$onInit = () => {
this.foldersById = _.keyBy(this.folders, 'id');
this.systemFoldersById = _.keyBy(this.systemFolders, 'id');
Expand All @@ -72,6 +77,27 @@ const NewPageComponent: ng.IComponentOptions = {
$state.go('management.settings.documentation', {parent: $state.params.parent});
}

const q = new DocumentationQuery();
q.type = PageType.MARKDOWN_TEMPLATE;
q.published = true;
q.translated = true;
DocumentationService.search(q, null)
.then(response => {
this.templates = response.data;

if (this.templates.length > 0) {
const emptyPage: Page = {
name: 'Empty page',
content: '',
type: PageType.MARKDOWN_TEMPLATE,
parentId: ''
};
this.templates.unshift(emptyPage);
this.selectedTemplate = emptyPage;
}

});

this.emptyFetcher = {
'type': 'object',
'id': 'empty',
Expand All @@ -89,6 +115,25 @@ const NewPageComponent: ng.IComponentOptions = {

};

this.getPageName = (): string => {
switch (this.page.type) {
case PageType.FOLDER:
return 'New Folder';
case PageType.LINK:
return 'New Link';
case PageType.MARKDOWN_TEMPLATE:
return 'New Markdown Template';
default:
return 'New Page';
}
};

this.isFolder = (): boolean => PageType.FOLDER === this.page.type;
this.isLink = (): boolean => PageType.LINK === this.page.type;
this.isSwagger = (): boolean => PageType.SWAGGER === this.page.type;
this.isMarkdown = (): boolean => PageType.MARKDOWN === this.page.type;
this.isMarkdownTemplate = (): boolean => PageType.MARKDOWN_TEMPLATE === this.page.type;

this.buildPageList = (pagesToFilter: any[], withRootFolder?: boolean) => {
let pageList = _
.filter(pagesToFilter, (p) => p.type === 'MARKDOWN' || p.type === 'SWAGGER' || (p.type === 'FOLDER' && this.getFolderSituation(p.id) !== FolderSituation.FOLDER_IN_SYSTEM_FOLDER))
Expand Down Expand Up @@ -187,6 +232,10 @@ const NewPageComponent: ng.IComponentOptions = {
}
};

this.onChangeMarkdownTemplate = () => {
this.page = {...this.page, content: this.selectedTemplate.content};
};

this.save = () => {
this.error = null;
DocumentationService.create(this.page, this.apiId)
Expand Down
Loading

0 comments on commit 6e55f52

Please sign in to comment.