2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 TechMahindra
6 *=================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 import { Component, OnInit, ViewChild } from '@angular/core';
22 import { IResources } from 'src/app/common/core/store/models/resources.model';
23 import { IResourcesState } from 'src/app/common/core/store/models/resourcesState.model';
24 import { LoadResourcesSuccess,UpdateResources,SetResourcesState } from 'src/app/common/core/store/actions/resources.action';
25 import { Store } from '@ngrx/store';
26 import { IAppState } from '../../../common/core/store/state/app.state';
27 import { JsonEditorComponent, JsonEditorOptions } from 'ang-jsoneditor';
28 import { Observable } from 'rxjs';
29 import { A11yModule } from '@angular/cdk/a11y';
30 import { ResourceEditService } from './resource-edit.service';
33 selector: 'app-resource-edit',
34 templateUrl: './resource-edit.component.html',
35 styleUrls: ['./resource-edit.component.scss']
37 export class ResourceEditComponent implements OnInit {
41 rdState: Observable<IResourcesState>;
42 designerMode: boolean = false;
43 editorMode: boolean = true;
44 viewText: string = "Open in Editor Mode";
45 @ViewChild(JsonEditorComponent) editor: JsonEditorComponent;
46 options = new JsonEditorOptions();
48 constructor(private store: Store<IAppState>, private resourceEditService: ResourceEditService) {
49 this.rdState = this.store.select('resources');
50 this.options.mode = 'text';
51 this.options.modes = [ 'text', 'tree', 'view'];
52 this.options.statusBar = false;
56 this.rdState.subscribe(
58 var resourcesState: IResourcesState = { resources: resourcesdata.resources, isLoadSuccess: resourcesdata.isLoadSuccess, isSaveSuccess: resourcesdata.isSaveSuccess, isUpdateSuccess: resourcesdata.isUpdateSuccess };
59 this.resources=resourcesState.resources;
63 metaDataDetail(data: IResources) {
67 sourcesDetails(data: IResources) {
72 this.data=JSON.parse($event.srcElement.value);
75 updateResourcesState(){
76 console.log(this.data);
77 let resourcesState = {
83 this.store.dispatch(new SetResourcesState(resourcesState));
87 if(this.viewText == 'Open in Editor Mode') {
88 this.editorMode = true;
89 this.designerMode = false;
90 this.viewText = 'Open in Form Mode'
92 this.editorMode = false;
93 this.designerMode = true;
94 this.viewText = 'Open in Editor Mode'
99 this.resourceEditService.saveResource(this.data)
100 .subscribe(response=>{
101 window.alert("save success");
104 window.alert('Error saving resources');