import { PackageCreationUtils } from '../../package-creation.utils';
import { JsonConvert, Any } from 'json2typescript';
import { ToastrService } from 'ngx-toastr';
+import { Router, ActivatedRoute } from '@angular/router';
+import { SharedService } from '../shared-service';
@Component({
selector: 'app-templ-mapp-creation',
mappingRes = [];
currentTemplate: any;
currentMapping: any;
+ edit = false;
constructor(
private packageCreationStore: PackageCreationStore,
private templateStore: TemplateStore,
private packageCreationUtils: PackageCreationUtils,
- private toastr: ToastrService
+ private toastr: ToastrService,
+ private router: ActivatedRoute,
+ private sharedService: SharedService
) {
}
ngOnInit() {
+ if (this.router.snapshot.paramMap.has('id')) {
+ console.log('URL contains Id');
+ this.sharedService.enableEdit();
+ }
+
this.templateStore.state$.subscribe(templateInfo => {
// init Template&mapping vars
- console.log('----------');
+ console.log('Oninit');
console.log(templateInfo);
this.templateInfo = templateInfo;
this.fileName = templateInfo.fileName.split('/')[1];
});
+ this.sharedService.isEdit().subscribe(res => {
+ console.log('------------------------');
+ console.log(res);
+ this.edit = res;
+
+ if (!this.edit) {
+ console.log('remove ----');
+ this.currentMapping = {};
+ this.currentTemplate = {};
+ this.fileName = '';
+ this.templateFileContent = '';
+ this.resourceDictionaryRes = [];
+ this.mappingRes = [];
+ }
+ });
+
this.dtOptions = {
pagingType: 'full_numbers',
pageLength: 25,
this.mappingRes = [];
this.currentMapping = {};
this.currentTemplate = {};
+ this.closeCreationForm();
}
saveToStore() {
if (this.fileName) {
// check file duplication
- if (!(this.packageCreationStore.fileExist('Templates/' + this.fileName + '-mapping.json')
- || this.packageCreationStore.fileExist('Templates/' + this.fileName + '-template' + this.getFileExtension()))) {
+ console.log('----------- mode ' + this.edit);
+ if (
+ (!(this.packageCreationStore.fileExist('Templates/' + this.fileName + '-mapping.json')
+ || this.packageCreationStore.fileExist('Templates/' + this.fileName + '-template' + this.getFileExtension())))
+ || this.edit
+ ) {
// Save Mapping to Store
if (this.resourceDictionaryRes && this.resourceDictionaryRes.length > 0) {
const mapArray = this.convertDictionaryToMap(this.resourceDictionaryRes);
import { TemplateInfo, TemplateStore } from '../../template.store';
import { TemplateAndMapping } from '../TemplateAndMapping';
import { ActivatedRoute } from '@angular/router';
+import { SharedService } from '../shared-service';
@Component({
private mapping: Mapping;
isCreate = true;
currentFile: string;
+ edit = false;
constructor(
private packageCreationStore: PackageCreationStore,
private templateStore: TemplateStore,
- private route: ActivatedRoute
+ private route: ActivatedRoute,
+ private sharedService: SharedService
) {
}
ngOnInit() {
if (this.route.snapshot.paramMap.has('id')) {
this.isCreate = false;
+ this.sharedService.isEdit().subscribe(res => {
+ this.edit = res;
+ });
+
}
this.packageCreationStore.state$.subscribe(cba => {
if (cba.templates) {
openCreationView() {
this.showCreationViewParentNotification.emit('tell parent to open create views');
+ console.log('disable edit mode');
+ this.sharedService.disableEdit();
+
}
FullView() {
this.showFullView.emit('show full view');
}
this.templateStore.changeTemplateInfo(templateInfo);
this.FullView();
+ this.sharedService.enableEdit();
});
}