import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from "@angular/router"; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { SystemVariables } from '../../../../models/admin/system/systemvariables/systemvariables'; import { SystemVariableService } from '../../../../services/admin/system/systemvariables/systemvariables.service'; import { CommonService } from '../../../../services/common.service'; @Component({ selector: 'app-system-variables', templateUrl: './system-variables.component.html', styleUrls: ['./system-variables.component.css'] }) export class SystemVariablesComponent implements OnInit { modelSystemVariables = new SystemVariables(); SystemVariablesForm: FormGroup; SystemVariablesAPIResponse: any; SysVariables: any; _paramId: number = 1; showModal: boolean = false; deleteModal; previewModal; historyModal; constructor( private formBuilder: FormBuilder, private route: ActivatedRoute, private service: SystemVariableService, private common: CommonService, private router: Router, ) { } ngOnInit(): void { this._paramId = Number(this.route.snapshot.params.id); this.setFormBuilder(); if (this._paramId == 0) { this.SystemVariablesForm = this.setAddForm(); } else { this.service.getSystemVariable(data => { this.SystemVariablesAPIResponse = data; this.modelSystemVariables = this.SystemVariablesAPIResponse.objResponse.responseContent; this.SystemVariablesForm = this.setEditForm(this.modelSystemVariables); }, (error) => { console.error('Error: ' + error); return error(error); }); } } showHistoryModal(historyFor) { this.showModal = true; this.historyModal = { historyFor: historyFor } this.previewModal = ""; this.deleteModal = ""; } setFormBuilder() { this.SystemVariablesForm = this.formBuilder.group({ SystemVariableId: [''], MinimumPasswordLength: [0, Validators.required], LoginConfirmationDays: [0, Validators.required], PasswordResetConfirmationDays: [''], LoginRetries: [''], SessionTimeout: ['', Validators.required], MaximumAttachmentSize: [''], AcceptableAttachmentTypes: [''], AcceptableLogoTypes: [''], SystemVersion: [''], CopyrightInformation: [''], NotificationSliderSpeed: [''], NoContentMessageOrders: [''], NoContentMessageQuotes: [''], NoContentMessageLeads: [''], NoContentMessageContacts: [''], NoContentMessageUpcomingEvents: [''], NoContentMessageFeatureAnnouncements: [''], NoContentMessageBuilderNews: [''], NoContentMessageJobBoard: [''], DailyNotificationTimeUtc: [''], WeeklyNotificationTimeUtc: [''], NotificationDayOfTheWeek: [''], ThrottlingThreshold: [''], ThrottlingDelay: [''], MultiLoginMessage: [''], FurthestShippingDays: [''], FramedOpeningClearanceTop: ['', [Validators.min(0), Validators.max(99999), Validators.pattern(/^[0-9]+(\.[0-9]{1,2})?$/)]], FramedOpeningClearanceBottom: [''], FramedOpeningClearanceSides: [''], FramedOpeningSideClearenceForMainFrameEndwalls: [''], TopClearenceForMainFrameEndwallsForFramedOpening: [''], FramedOpeningSideClearanceForBearingFrameEndwalls: [''], FramedOpeningTopClearanceForBearingFrameEndwalls: [''], MaxValueForEndwallBSpecialSetback: [''], MaximumVerticalClearanceRequirement: [''], MinValueForEndwallBSpecialSetback: [''], MinValueForEndwallDSpecialSetback: [''], MinimumCanopySoffitElevation: [''], ParapetMinimumDistanceAboveRoofLine: [''], TopClearenceForMainFrameEndwallsForDbciDoor: [''], DbciDoorClearanceTop: [''], DbciDoorClearanceBottom: [''], DbciDoorClearanceSides: [''], DbciDoorTopClearanceForBearingFrameEndwalls: [''], DBCIDoorSideClearanceMainFrame: [''], DBCIDoorSideClearanceBearingFrame: [''], PortalFrameColumnDepth: [''], PortalFrameBeamDepth: [''], FerryFee: [''], ThreeWeekFee: [''], NumberOfItemsPerPage: [''], AgoraPurchaseOrderVersion: [''], ComponentPurchaseOrderVersion: [''], ComponentPricingVersion: [''], BuildingPricingVersionNumber: [''], FurthestShippingDaysForComponent: [''], FurthestShippingDaysBuilding: [''], }); } setAddForm(): FormGroup { return this.formBuilder.group({ SystemVariableId: 0, MinimumPasswordLength: [0, Validators.required], LoginConfirmationDays: [0, Validators.required], PasswordResetConfirmationDays: 0, LoginRetries: [''], SessionTimeout: [0, Validators.required], MaximumAttachmentSize: 0, AcceptableAttachmentTypes: '', AcceptableLogoTypes: '', SystemVersion: '', CopyrightInformation: '', NotificationSliderSpeed: 0, NoContentMessageOrders: '', NoContentMessageQuotes: '', NoContentMessageLeads: '', NoContentMessageContacts: '', NoContentMessageUpcomingEvents: '', NoContentMessageFeatureAnnouncements: '', NoContentMessageBuilderNews: '', NoContentMessageJobBoard: '', DailyNotificationTimeUtc: "", WeeklyNotificationTimeUtc: "", NotificationDayOfTheWeek: 0, ThrottlingThreshold: 0, ThrottlingDelay: 0, MultiLoginMessage: '', FurthestShippingDays: 0, //Only Agora properties FramedOpeningClearanceTop: 0, FramedOpeningClearanceBottom: 0, FramedOpeningClearanceSides: 0, FramedOpeningSideClearenceForMainFrameEndwalls: 0, TopClearenceForMainFrameEndwallsForFramedOpening: 0, FramedOpeningSideClearanceForBearingFrameEndwalls: 0, FramedOpeningTopClearanceForBearingFrameEndwalls: 0, MaxValueForEndwallBSpecialSetback: 0, MaximumVerticalClearanceRequirement: '', MinValueForEndwallBSpecialSetback: 0, MinValueForEndwallDSpecialSetback: 0, MinimumCanopySoffitElevation: 0, ParapetMinimumDistanceAboveRoofLine: 0, TopClearenceForMainFrameEndwallsForDbciDoor: 0, DbciDoorClearanceTop: 0, DbciDoorClearanceBottom: 0, DbciDoorClearanceSides: 0, DbciDoorTopClearanceForBearingFrameEndwalls: 0, DBCIDoorSideClearanceMainFrame: 0, DBCIDoorSideClearanceBearingFrame: 0, PortalFrameColumnDepth: 0, PortalFrameBeamDepth: 0, FerryFee: 0, ThreeWeekFee: 0, NumberOfItemsPerPage: 0, AgoraPurchaseOrderVersion: '', ComponentPurchaseOrderVersion: '', ComponentPricingVersion: '', BuildingPricingVersionNumber: '', FurthestShippingDaysForComponent: 0, FurthestShippingDaysBuilding: 0, }); } setEditForm(data): FormGroup { return this.formBuilder.group({ SystemVariableId: data.SystemVariableId == null ? 0 : data.SystemVariableId, MinimumPasswordLength: [data.MinimumPasswordLength == null ? 0 : data.MinimumPasswordLength, [Validators.required]], LoginConfirmationDays: [data.LoginConfirmationDays == null ? 0 : data.LoginConfirmationDays, [Validators.required]], PasswordResetConfirmationDays: data.PasswordResetConfirmationDays == null ? 0 : data.PasswordResetConfirmationDays, LoginRetries: data.LoginRetries == null ? 0 : data.LoginRetries, SessionTimeout: [data.SessionTimeout == null ? 0 : data.SessionTimeout, [Validators.required]], MaximumAttachmentSize: data.MaximumAttachmentSize == null ? 0 : data.MaximumAttachmentSize, AcceptableAttachmentTypes: data.AcceptableAttachmentTypes == null ? "" : data.AcceptableAttachmentTypes, AcceptableLogoTypes: data.AcceptableLogoTypes == null ? "" : data.AcceptableLogoTypes, SystemVersion: data.SystemVersion == null ? "" : data.SystemVersion, CopyrightInformation: data.CopyrightInformation == null ? "" : data.CopyrightInformation, NotificationSliderSpeed: data.NotificationSliderSpeed == null ? 0 : data.NotificationSliderSpeed, NoContentMessageOrders: data.NoContentMessageOrders == null ? "" : data.NoContentMessageOrders, NoContentMessageQuotes: data.NoContentMessageQuotes == null ? "" : data.NoContentMessageQuotes, NoContentMessageLeads: data.NoContentMessageLeads == null ? "" : data.NoContentMessageLeads, NoContentMessageContacts: data.NoContentMessageContacts == null ? "" : data.NoContentMessageContacts, NoContentMessageUpcomingEvents: data.NoContentMessageUpcomingEvents == null ? "" : data.NoContentMessageUpcomingEvents, NoContentMessageFeatureAnnouncements: data.NoContentMessageFeatureAnnouncements == null ? "" : data.NoContentMessageFeatureAnnouncements, NoContentMessageBuilderNews: data.NoContentMessageBuilderNews == null ? "" : data.NoContentMessageBuilderNews, NoContentMessageJobBoard: data.NoContentMessageJobBoard == null ? "" : data.NoContentMessageJobBoard, DailyNotificationTimeUtc: data.DailyNotificationTimeUtc == null ? "" : data.DailyNotificationTimeUtc, WeeklyNotificationTimeUtc: data.WeeklyNotificationTimeUtc == null ? "" : data.WeeklyNotificationTimeUtc, NotificationDayOfTheWeek: data.NotificationDayOfTheWeek == null ? 0 : data.NotificationDayOfTheWeek, ThrottlingThreshold: data.ThrottlingThreshold == null ? 0 : data.ThrottlingThreshold, ThrottlingDelay: data.ThrottlingDelay == null ? 0 : data.ThrottlingDelay, MultiLoginMessage: data.MultiLoginMessage == null ? "" : data.MultiLoginMessage, FurthestShippingDays: data.FurthestShippingDays == null ? 0 : data.FurthestShippingDays, FramedOpeningClearanceTop: [data.FramedOpeningClearanceTop == null ? 0 : data.FramedOpeningClearanceTop, [Validators.min(0), Validators.max(99999), Validators.pattern(/^[0-9]+(\.[0-9]{1,2})?$/)]], FramedOpeningClearanceBottom: data.FramedOpeningClearanceBottom == null ? 0 : data.FramedOpeningClearanceBottom, FramedOpeningClearanceSides: data.FramedOpeningClearanceSides == null ? 0 : data.FramedOpeningClearanceSides, FramedOpeningSideClearenceForMainFrameEndwalls: data.FramedOpeningSideClearenceForMainFrameEndwalls == null ? 0 : data.FramedOpeningSideClearenceForMainFrameEndwalls, TopClearenceForMainFrameEndwallsForFramedOpening: data.TopClearenceForMainFrameEndwallsForFramedOpening == null ? 0 : data.TopClearenceForMainFrameEndwallsForFramedOpening, FramedOpeningSideClearanceForBearingFrameEndwalls: data.FramedOpeningSideClearanceForBearingFrameEndwalls == null ? 0 : data.FramedOpeningSideClearanceForBearingFrameEndwalls, FramedOpeningTopClearanceForBearingFrameEndwalls: data.FramedOpeningTopClearanceForBearingFrameEndwalls == null ? 0 : data.FramedOpeningTopClearanceForBearingFrameEndwalls, MaxValueForEndwallBSpecialSetback: data.MaxValueForEndwallBSpecialSetback == null ? 0 : data.MaxValueForEndwallBSpecialSetback, MaximumVerticalClearanceRequirement: data.MaximumVerticalClearanceRequirement == null ? 0 : data.MaximumVerticalClearanceRequirement, MinValueForEndwallBSpecialSetback: data.MinValueForEndwallBSpecialSetback == null ? 0 : data.MinValueForEndwallBSpecialSetback, MinValueForEndwallDSpecialSetback: data.MinValueForEndwallDSpecialSetback == null ? 0 : data.MinValueForEndwallDSpecialSetback, MinimumCanopySoffitElevation: data.MinimumCanopySoffitElevation == null ? 0 : data.MinimumCanopySoffitElevation, ParapetMinimumDistanceAboveRoofLine: data.ParapetMinimumDistanceAboveRoofLine == null ? 0 : data.ParapetMinimumDistanceAboveRoofLine, TopClearenceForMainFrameEndwallsForDbciDoor: data.TopClearenceForMainFrameEndwallsForDbciDoor == null ? 0 : data.TopClearenceForMainFrameEndwallsForDbciDoor, DbciDoorClearanceTop: data.DbciDoorClearanceTop == null ? 0 : data.DbciDoorClearanceTop, DbciDoorClearanceBottom: data.DbciDoorClearanceBottom == null ? 0 : data.DbciDoorClearanceBottom, DbciDoorClearanceSides: data.DbciDoorClearanceSides == null ? 0 : data.DbciDoorClearanceSides, DbciDoorTopClearanceForBearingFrameEndwalls: data.DbciDoorTopClearanceForBearingFrameEndwalls == null ? 0 : data.DbciDoorTopClearanceForBearingFrameEndwalls, DBCIDoorSideClearanceMainFrame: data.DBCIDoorSideClearanceMainFrame == null ? 0 : data.DBCIDoorSideClearanceMainFrame, DBCIDoorSideClearanceBearingFrame: data.DBCIDoorSideClearanceBearingFrame == null ? 0 : data.DBCIDoorSideClearanceBearingFrame, PortalFrameColumnDepth: data.PortalFrameColumnDepth == null ? 0 : data.PortalFrameColumnDepth, PortalFrameBeamDepth: data.PortalFrameBeamDepth == null ? 0 : data.PortalFrameBeamDepth, FerryFee: data.FerryFee == null ? 0 : data.FerryFee, ThreeWeekFee: data.ThreeWeekFee == null ? 0 : data.ThreeWeekFee, NumberOfItemsPerPage: data.NumberOfItemsPerPage == null ? 0 : data.NumberOfItemsPerPage, AgoraPurchaseOrderVersion: data.AgoraPurchaseOrderVersion == null ? "" : data.AgoraPurchaseOrderVersion, ComponentPurchaseOrderVersion: data.ComponentPurchaseOrderVersion == null ? "" : data.ComponentPurchaseOrderVersion, ComponentPricingVersion: data.ComponentPricingVersion == null ? "" : data.ComponentPricingVersion, BuildingPricingVersionNumber: data.BuildingPricingVersionNumber == null ? "" : data.BuildingPricingVersionNumber, FurthestShippingDaysForComponent: data.FurthestShippingDaysForComponent == null ? 0 : data.FurthestShippingDaysForComponent, FurthestShippingDaysBuilding: data.FurthestShippingDaysBuilding == null ? 0 : data.FurthestShippingDaysBuilding, }); } submitform() { if (this.SystemVariablesForm.valid) { this.modelSystemVariables = this.SystemVariablesForm.value; this.setModelBeforeSubmit(); this.service.saveSystemVariable(this.modelSystemVariables, data => { this.SystemVariablesAPIResponse = data; if (this.SystemVariablesAPIResponse.objResponse.statusCode == "200") { this.common.showSuccess("System variable changes applied successfully.", "Success") } else { this.common.showError("Transaction not completed.", "Transaction Fail") } }, (error) => { console.error('Error: ' + error); return error(error); }); } else { const invalid = []; const controls = this.SystemVariablesForm.controls; for (const name in controls) { if (controls[name].invalid) { invalid.push(name); } } } } setModelBeforeSubmit() { this.modelSystemVariables.SystemVariableId = Number(this.modelSystemVariables.SystemVariableId); this.modelSystemVariables.MinimumPasswordLength = Number(this.modelSystemVariables.MinimumPasswordLength); this.modelSystemVariables.LoginConfirmationDays = Number(this.modelSystemVariables.LoginConfirmationDays); this.modelSystemVariables.PasswordResetConfirmationDays = Number(this.modelSystemVariables.PasswordResetConfirmationDays); this.modelSystemVariables.LoginRetries = Number(this.modelSystemVariables.LoginRetries); this.modelSystemVariables.SessionTimeout = Number(this.modelSystemVariables.SessionTimeout); this.modelSystemVariables.MaximumAttachmentSize = Number(this.modelSystemVariables.MaximumAttachmentSize); this.modelSystemVariables.AcceptableAttachmentTypes = String(this.modelSystemVariables.AcceptableAttachmentTypes); this.modelSystemVariables.AcceptableLogoTypes = String(this.modelSystemVariables.AcceptableLogoTypes); this.modelSystemVariables.SystemVersion = String(this.modelSystemVariables.SystemVersion); this.modelSystemVariables.CopyrightInformation = String(this.modelSystemVariables.CopyrightInformation); this.modelSystemVariables.NotificationSliderSpeed = Number(this.modelSystemVariables.NotificationSliderSpeed); this.modelSystemVariables.NoContentMessageOrders = String(this.modelSystemVariables.NoContentMessageOrders); this.modelSystemVariables.NoContentMessageQuotes = String(this.modelSystemVariables.NoContentMessageQuotes); this.modelSystemVariables.NoContentMessageLeads = String(this.modelSystemVariables.NoContentMessageLeads); this.modelSystemVariables.NoContentMessageContacts = String(this.modelSystemVariables.NoContentMessageContacts); this.modelSystemVariables.NoContentMessageUpcomingEvents = String(this.modelSystemVariables.NoContentMessageUpcomingEvents); this.modelSystemVariables.NoContentMessageFeatureAnnouncements = String(this.modelSystemVariables.NoContentMessageFeatureAnnouncements); this.modelSystemVariables.NoContentMessageBuilderNews = String(this.modelSystemVariables.NoContentMessageBuilderNews); this.modelSystemVariables.NoContentMessageJobBoard = String(this.modelSystemVariables.NoContentMessageJobBoard); this.modelSystemVariables.DailyNotificationTimeUtc = String(this.modelSystemVariables.DailyNotificationTimeUtc); this.modelSystemVariables.WeeklyNotificationTimeUtc = String(this.modelSystemVariables.WeeklyNotificationTimeUtc); this.modelSystemVariables.NotificationDayOfTheWeek = String(this.modelSystemVariables.NotificationDayOfTheWeek); this.modelSystemVariables.ThrottlingThreshold = Number(this.modelSystemVariables.ThrottlingThreshold); this.modelSystemVariables.ThrottlingDelay = Number(this.modelSystemVariables.ThrottlingDelay); this.modelSystemVariables.MultiLoginMessage = String(this.modelSystemVariables.MultiLoginMessage); this.modelSystemVariables.FurthestShippingDays = Number(this.modelSystemVariables.FurthestShippingDays); //Only Agora properties this.modelSystemVariables.FramedOpeningClearanceTop = Number(this.modelSystemVariables.FramedOpeningClearanceTop); this.modelSystemVariables.FramedOpeningClearanceBottom = Number(this.modelSystemVariables.FramedOpeningClearanceBottom); this.modelSystemVariables.FramedOpeningClearanceSides = Number(this.modelSystemVariables.FramedOpeningClearanceSides); this.modelSystemVariables.FramedOpeningSideClearenceForMainFrameEndwalls = Number(this.modelSystemVariables.FramedOpeningSideClearenceForMainFrameEndwalls); this.modelSystemVariables.TopClearenceForMainFrameEndwallsForFramedOpening = Number(this.modelSystemVariables.TopClearenceForMainFrameEndwallsForFramedOpening); this.modelSystemVariables.FramedOpeningSideClearanceForBearingFrameEndwalls = Number(this.modelSystemVariables.FramedOpeningSideClearanceForBearingFrameEndwalls); this.modelSystemVariables.FramedOpeningTopClearanceForBearingFrameEndwalls = Number(this.modelSystemVariables.FramedOpeningTopClearanceForBearingFrameEndwalls); this.modelSystemVariables.MaxValueForEndwallBSpecialSetback = Number(this.modelSystemVariables.MaxValueForEndwallBSpecialSetback); this.modelSystemVariables.MaximumVerticalClearanceRequirement = Number(this.modelSystemVariables.MaximumVerticalClearanceRequirement); this.modelSystemVariables.MinValueForEndwallBSpecialSetback = Number(this.modelSystemVariables.MinValueForEndwallBSpecialSetback); this.modelSystemVariables.MinValueForEndwallDSpecialSetback = Number(this.modelSystemVariables.MinValueForEndwallDSpecialSetback); this.modelSystemVariables.MinimumCanopySoffitElevation = Number(this.modelSystemVariables.MinimumCanopySoffitElevation); this.modelSystemVariables.ParapetMinimumDistanceAboveRoofLine = Number(this.modelSystemVariables.ParapetMinimumDistanceAboveRoofLine); this.modelSystemVariables.TopClearenceForMainFrameEndwallsForDbciDoor = Number(this.modelSystemVariables.TopClearenceForMainFrameEndwallsForDbciDoor); this.modelSystemVariables.DbciDoorClearanceTop = Number(this.modelSystemVariables.DbciDoorClearanceTop); this.modelSystemVariables.DbciDoorClearanceBottom = Number(this.modelSystemVariables.DbciDoorClearanceBottom); this.modelSystemVariables.DbciDoorClearanceSides = Number(this.modelSystemVariables.DbciDoorClearanceSides); this.modelSystemVariables.DbciDoorTopClearanceForBearingFrameEndwalls = Number(this.modelSystemVariables.DbciDoorTopClearanceForBearingFrameEndwalls); this.modelSystemVariables.DBCIDoorSideClearanceMainFrame = Number(this.modelSystemVariables.DBCIDoorSideClearanceMainFrame); this.modelSystemVariables.DBCIDoorSideClearanceBearingFrame = Number(this.modelSystemVariables.DBCIDoorSideClearanceBearingFrame); this.modelSystemVariables.PortalFrameColumnDepth = Number(this.modelSystemVariables.PortalFrameColumnDepth); this.modelSystemVariables.PortalFrameBeamDepth = Number(this.modelSystemVariables.PortalFrameBeamDepth); this.modelSystemVariables.FerryFee = Number(this.modelSystemVariables.FerryFee); this.modelSystemVariables.ThreeWeekFee = Number(this.modelSystemVariables.ThreeWeekFee); this.modelSystemVariables.NumberOfItemsPerPage = Number(this.modelSystemVariables.NumberOfItemsPerPage); this.modelSystemVariables.AgoraPurchaseOrderVersion = String(this.modelSystemVariables.AgoraPurchaseOrderVersion); this.modelSystemVariables.ComponentPurchaseOrderVersion = String(this.modelSystemVariables.ComponentPurchaseOrderVersion); this.modelSystemVariables.ComponentPricingVersion = String(this.modelSystemVariables.ComponentPricingVersion); this.modelSystemVariables.BuildingPricingVersionNumber = String(this.modelSystemVariables.BuildingPricingVersionNumber); this.modelSystemVariables.FurthestShippingDaysForComponent = Number(this.modelSystemVariables.FurthestShippingDaysForComponent); this.modelSystemVariables.FurthestShippingDaysBuilding = Number(this.modelSystemVariables.FurthestShippingDaysBuilding); } gotoList() { this.router.navigate(["/admin/admin-system"]); } displayFieldCss(field: string, ctrlType: string) { if (ctrlType.toLowerCase() == "txt") { return { 'plain-valid': this.SystemVariablesForm.get(field).valid, 'is-invalid': (this.SystemVariablesForm.get(field).invalid && (this.SystemVariablesForm.get(field).dirty || this.SystemVariablesForm.get(field).touched)) }; } else { return { 'plain-valid': this.SystemVariablesForm.get(field).valid, 'plain-invalid': (this.SystemVariablesForm.get(field).invalid && (this.SystemVariablesForm.get(field).dirty || this.SystemVariablesForm.get(field).touched)) }; } } }