Skip to content

Commit

Permalink
add options to config for view link
Browse files Browse the repository at this point in the history
  • Loading branch information
Doris Lam committed Nov 13, 2023
1 parent 3d269e3 commit 363eb0a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions config/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
"labels": ["opensource"]
},
"loginTimout": 600000,
"viewLink": {
"sectionPrefix": "Section ",
"appendixPrefix": "Appendix ",
"hidePrefixForSections": false
},
"experimental": [
{
"id": "experimental-magic",
Expand Down
19 changes: 17 additions & 2 deletions src/ve-components/presentations/mms-view-link.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { veComponents } from '@ve-components';

import { VeComponentOptions } from '@ve-types/angular';
import { ElementObject, ElementsRequest } from '@ve-types/mms';
import {VeConfig} from "@ve-types/config";

/**
* @ngdoc directive
Expand Down Expand Up @@ -77,6 +78,7 @@ class ViewLinkController implements angular.IComponentController {
private docid: string;
showNum: boolean;
vid: string;
private veConfig: VeConfig;

constructor(
private $scope: angular.IScope,
Expand All @@ -88,7 +90,9 @@ class ViewLinkController implements angular.IComponentController {
private viewSvc: ViewService,
private applicationSvc: ApplicationService,
private extensionSvc: ExtensionService
) {}
) {
this.veConfig = window.__env;
}

$onInit(): void {
this.target = this.linkTarget ? this.linkTarget : '_self';
Expand Down Expand Up @@ -146,7 +150,7 @@ class ViewLinkController implements angular.IComponentController {
(data: ElementObject) => {
this.element = data;
this.elementName = data.name;
this.type = 'Section ';
this.type = this.veConfig.viewLink.sectionPrefix;
this.suffix = '';
this.hash = '#' + data.id;
if (this.mmsPeId && this.mmsPeId !== '') {
Expand All @@ -168,6 +172,8 @@ class ViewLinkController implements angular.IComponentController {
} else if (this.viewSvc.isEquation(pe)) {
this.type = 'Eq. (';
this.suffix = ')';
} else if (this.viewSvc.isSection(pe) && this.veConfig.viewLink.hidePrefixForSections) {
this.type = '';
}
if (this.applicationSvc.getState().fullDoc) {
this.href = `main.project.ref.view.present.document({ projectId: $ctrl.projectId, refId: $ctrl.refId, documentId: $ctrl.docid, viewId: $ctrl.vid })`;
Expand All @@ -179,6 +185,15 @@ class ViewLinkController implements angular.IComponentController {
this.growl.warning(`Unable to retrieve element: ${reason.message}`);
}
);
} else {
if (data._veNumber) {
let numbers = data._veNumber.split('.');
if (numbers.length > 1 && this.veConfig.viewLink.hidePrefixForSections) {
this.type = '';
} else if (isNaN(parseInt(numbers[0]))) {
this.type = this.veConfig.viewLink.appendixPrefix;
}
}
}
if (this.apiSvc.isDocument(data)) {
docid = data.id;
Expand Down
5 changes: 5 additions & 0 deletions src/ve-types/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export interface VeConfig {
banner?: BrandingStyle;
footer?: BrandingStyle;
loginTimeout?: number;
viewLink: {
sectionPrefix: string;
appendixPrefix: string;
hidePrefixForSections: boolean;
}
experimental?: VeExperimentDescriptor[];
expConfig?: VeExperimentConfig;
}

0 comments on commit 363eb0a

Please sign in to comment.