AleksanderSklorz 98c0a3c7be
[ACS-5041] update license headers to reflect hyland copyright guidelines (#8472)
* ACS-5041 Changed json to js

* ACS-5041 Corrected paths

* ACS-5041 Changed json to js

* ACS-5041 Updated eslintrc

* ACS-5041 Small correction

* ACS-5041 Small correction

* ACS-5041 Updated license headers

* ACS-5041 Updated license headers

* ACS-5041 Replaced references to alfresco

* ACS-5041 Added Hyland to known words

* ACS-5041 Fixed coverage issue

* ACS-5041 Fixed duplication issue

* ACS-5041 Fixed duplications issue

* ACS-5041 Fixed duplications issue

* ACS-5041 Fixed duplications issue

* ACS-5041 Fixed duplications issue

* ACS-5041 Fixed duplications issue

* ACS-5041 Fixed duplications issue

* ACS-5041 Fixed duplications issue

* ACS-5041 Fixed duplications issue

* ACS-5041 Fixed test

* ACS-5041 Fixed test

* ACS-5041 Reverted one change

* ACS-5041 Added missing license to files after rebase
2023-04-20 09:34:03 +02:00

144 lines
4.3 KiB
TypeScript

/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
import { Component, OnDestroy } from '@angular/core';
import {
AppConfigService,
NotificationService,
UserPreferencesService,
UserPreferenceValues
} from '@alfresco/adf-core';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Component({
selector: 'app-config-editor',
templateUrl: './config-editor.component.html',
styleUrls: ['./config-editor.component.scss']
})
export class ConfigEditorComponent implements OnDestroy {
private onDestroy$ = new Subject<boolean>();
editor: any;
code: any;
field: string;
invalidJson = false;
isUserPreference = false;
userPreferenceProperty: string;
editorOptions = {
theme: 'vs-dark',
language: 'json',
autoIndent: true,
formatOnPaste: true,
formatOnType: true
};
onInit(editor) {
this.editor = editor;
this.indentCode();
}
constructor(private appConfig: AppConfigService,
private userPreferencesService: UserPreferencesService,
private notificationService: NotificationService) {
this.code = JSON.stringify(appConfig.config);
}
onSave() {
try {
if (this.isUserPreference) {
this.userPreferencesService.set(this.userPreferenceProperty, JSON.parse(this.editor.getValue()));
} else {
this.appConfig.config = JSON.parse(this.editor.getValue());
}
} catch (error) {
this.invalidJson = true;
this.notificationService.openSnackMessage('Wrong Code configuration ' + error);
} finally {
if (!this.invalidJson) {
this.notificationService.openSnackMessage('Saved');
}
}
}
onClear() {
this.code = '';
}
appConfigClick() {
this.isUserPreference = false;
this.code = JSON.stringify(this.appConfig.config);
this.indentCode();
}
ngOnDestroy() {
this.onDestroy$.next(true);
this.onDestroy$.complete();
}
textOrientationClick() {
this.isUserPreference = true;
this.userPreferenceProperty = 'textOrientation';
this.userPreferencesService
.select(this.userPreferenceProperty)
.pipe(takeUntil(this.onDestroy$))
.subscribe((textOrientation: number) => {
this.code = JSON.stringify(textOrientation);
this.field = 'textOrientation';
this.indentCode();
});
this.indentCode();
}
infinitePaginationConfClick() {
this.isUserPreference = true;
this.userPreferenceProperty = UserPreferenceValues.PaginationSize;
this.userPreferencesService
.select(this.userPreferenceProperty)
.pipe(takeUntil(this.onDestroy$))
.subscribe((pageSize: number) => {
this.code = JSON.stringify(pageSize);
this.field = 'adf-infinite-pagination';
this.indentCode();
});
}
supportedPageSizesClick() {
this.isUserPreference = true;
this.userPreferenceProperty = UserPreferenceValues.SupportedPageSizes;
this.userPreferencesService
.select(this.userPreferenceProperty)
.pipe(takeUntil(this.onDestroy$))
.subscribe((supportedPageSizes: number) => {
this.code = JSON.stringify(supportedPageSizes);
this.field = 'adf-supported-page-size';
this.indentCode();
});
}
indentCode() {
setTimeout(() => {
this.editor.getAction('editor.action.formatDocument').run();
}, 300);
}
}