1/**
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { ILayoutConfig } from './ILayoutConfig';
17import { CommonConstants } from '../constants/CommonConstants';
18import formLayoutInfo from '../configs/FormLayoutInfo';
19
20/**
21 * Form layout configuration
22 */
23export class FormLayoutConfig extends ILayoutConfig {
24
25  /**
26   *  The index of form layout configuration
27   */
28  static FORM_LAYOUT_INFO = 'FormLayoutInfo';
29  protected mFormLayoutInfo: any = formLayoutInfo;
30
31  constructor() {
32    super();
33  }
34
35  /**
36   * Get folder layout configuration instance
37   */
38  static getInstance(): FormLayoutConfig {
39    if (globalThis.FormLayoutConfigInstance == null) {
40      globalThis.FormLayoutConfigInstance = new FormLayoutConfig();
41      globalThis.FormLayoutConfigInstance.initConfig();
42    }
43    return globalThis.FormLayoutConfigInstance;
44  }
45
46  initConfig(): void {
47    const config = this.loadPersistConfig();
48    this.mFormLayoutInfo = config;
49  }
50
51  getConfigLevel(): string {
52    return CommonConstants.LAYOUT_CONFIG_LEVEL_COMMON;
53  }
54
55  getConfigType(): number {
56    return CommonConstants.LAYOUT_CONFIG_TYPE_FUNCTION;
57  }
58
59  getConfigName(): string {
60    return FormLayoutConfig.FORM_LAYOUT_INFO;
61  }
62
63  getPersistConfigJson(): string {
64    return JSON.stringify(this.mFormLayoutInfo);
65  }
66
67  /**
68   * Update form layout data
69   *
70   * @params {gridLayoutInfo} form layout data
71   */
72  updateFormLayoutInfo(formLayoutInfo: object): void {
73    this.mFormLayoutInfo = formLayoutInfo;
74    super.persistConfig();
75  }
76
77  /**
78   * Get form layout data
79   *
80   * @return form layout data
81   */
82  getFormLayoutInfo(): any {
83    return this.mFormLayoutInfo;
84  }
85}
86