webpackJsonp([16],{

/***/ 1208:
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ModuleConfigPageModule", function() { return ModuleConfigPageModule; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__angular_core__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_ionic_angular__ = __webpack_require__(14);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__module_config__ = __webpack_require__(1460);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__modules_dynamic_form_dynamic_form_module__ = __webpack_require__(784);
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};




var ModuleConfigPageModule = /** @class */ (function () {
    function ModuleConfigPageModule() {
    }
    ModuleConfigPageModule = __decorate([
        Object(__WEBPACK_IMPORTED_MODULE_0__angular_core__["NgModule"])({
            declarations: [
                __WEBPACK_IMPORTED_MODULE_2__module_config__["a" /* ModuleConfigPage */],
            ],
            imports: [
                __WEBPACK_IMPORTED_MODULE_3__modules_dynamic_form_dynamic_form_module__["a" /* DynamicFormModule */],
                __WEBPACK_IMPORTED_MODULE_1_ionic_angular__["i" /* IonicPageModule */].forChild(__WEBPACK_IMPORTED_MODULE_2__module_config__["a" /* ModuleConfigPage */]),
            ],
        })
    ], ModuleConfigPageModule);
    return ModuleConfigPageModule;
}());

//# sourceMappingURL=module-config.module.js.map

/***/ }),

/***/ 1460:
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
/* unused harmony export AppSettings */
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return ModuleConfigPage; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__angular_core__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_ionic_angular__ = __webpack_require__(14);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__modules_dynamic_form_containers_dynamic_form_dynamic_form_component__ = __webpack_require__(783);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__angular_forms__ = __webpack_require__(26);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_ngx_logger__ = __webpack_require__(7);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__ncinga_sp_nsp_app_core_dist_cache_settings__ = __webpack_require__(55);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__providers_activation_service_activation_service__ = __webpack_require__(142);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__ionic_native_screen_orientation__ = __webpack_require__(259);
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};








/**
 * Generated class for the ModuleConfigPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */
var AppSettings = /** @class */ (function () {
    function AppSettings(obj) {
        this.id = obj && obj.id;
        this.app_type = obj && obj.app_type;
        this.app_name = obj && obj.app_name;
        this.configs = obj && obj.configs;
    }
    return AppSettings;
}());

var ModuleConfigPage = /** @class */ (function () {
    function ModuleConfigPage(navCtrl, navParams, logger, orientation, settings, actSvc) {
        this.navCtrl = navCtrl;
        this.navParams = navParams;
        this.logger = logger;
        this.orientation = orientation;
        this.settings = settings;
        this.actSvc = actSvc;
        this.APP_CONTEXT = 'bctx';
        this.landscape = true;
        this.config = [];
        this.preSettingsByApp = [];
        this.optionsMap = {};
        this.initModel();
    }
    ModuleConfigPage.prototype.ionViewDidLoad = function () {
        this.initForm();
    };
    ModuleConfigPage.prototype.initModel = function () {
        var _this = this;
        var args = this.navParams.get('options');
        this.tenant = this.navParams.get('tenant');
        this.subject_key = this.navParams.get('subject_key');
        if (args && args.length) {
            var presettingargs_1 = [];
            args.forEach(function (arg) {
                arg.settings.forEach(function (inp) {
                    /*
                     * TODO:define presettings options
                     * */
                    presettingargs_1.push({
                        validation: [__WEBPACK_IMPORTED_MODULE_3__angular_forms__["h" /* Validators */].required],
                        name: inp.arg_id,
                        type: inp.arg_type,
                        data_type: inp.data_type,
                        label: inp.name,
                        multiple: inp.multiple,
                        placeholder: inp.name,
                        s_name: inp.s_name,
                        s_value: inp.s_value
                    });
                });
                presettingargs_1.push({
                    label: 'Submit',
                    name: 'submit',
                    type: 'button'
                });
                _this.preSettingsByApp.push(new AppSettings({
                    id: arg.app_id,
                    app_name: arg.app_name,
                    app_type: arg.product_type,
                    configs: presettingargs_1
                }));
                presettingargs_1 = [];
            });
            this.loadTestData(this.preSettingsByApp);
        }
    };
    ModuleConfigPage.prototype.loadTestData = function (configs) {
        var _this = this;
        var dataToRequest = [];
        this.preSettingsByApp.forEach(function (appsetting) {
            appsetting.configs.forEach(function (item) {
                if (item.type === 'select') {
                    dataToRequest.push(item.data_type);
                }
            });
        });
        if (dataToRequest.length > 0) {
            this.actSvc.getPreSettingsData(this.tenant, this.subject_key, dataToRequest).subscribe(function (res) {
                // this.config = configs;
                _this.preSettingsByApp.forEach(function (appsetting) {
                    appsetting.configs.forEach(function (item) {
                        if (item.type === 'select') {
                            var options = res.result.filter(function (entry) {
                                if (entry.hasOwnProperty(item.data_type) && entry.app_type === appsetting.app_type) {
                                    return true;
                                }
                            });
                            if (options.length > 0) {
                                var dataoptions = _this._changeintoSelectData(options[0][item.data_type], item);
                                item.options = dataoptions;
                                // keep for later processing when save into locakstorage
                                _this.optionsMap[item.name] = dataoptions;
                            }
                        }
                    });
                });
            });
        }
    };
    ModuleConfigPage.prototype._changeintoSelectData = function (arr, conf) {
        var data = [];
        try {
            arr.forEach(function (item) {
                data.push({ name: item[conf['s_name']], id: item[conf['s_value']] });
            });
        }
        catch (e) {
            return data;
        }
        return data;
    };
    ModuleConfigPage.prototype.initForm = function () {
        var _this = this;
        var previousValid = this.form.valid;
        this.form.changes.subscribe(function () {
            if (_this.form.valid !== previousValid) {
                previousValid = _this.form.valid;
                _this.form.setDisabled('submit', !previousValid);
            }
        });
        this.form.setDisabled('submit', true);
    };
    /*
     * save module config values here
     * */
    ModuleConfigPage.prototype.submit = function (value, appType, settings) {
        var _this = this;
        if (value) {
            value['tenant'] = this.tenant;
            value['subject_key'] = this.subject_key;
        }
        var mode = (this.landscape) ? this.orientation.ORIENTATIONS.LANDSCAPE : this.orientation.ORIENTATIONS.PORTRAIT;
        this.settings.setValue('orientation', mode);
        this.orientation.lock(mode);
        var _loop_1 = function (key) {
            if (this_1.optionsMap.hasOwnProperty(key)) {
                var selectedOpts = this_1.optionsMap[key].filter(function (item) {
                    if (value[key].indexOf(item.id) > -1) {
                        return true;
                    }
                });
                value[key] = selectedOpts;
            }
        };
        var this_1 = this;
        /*
         * prepare subjects list and save
         * */
        for (var key in value) {
            _loop_1(key);
        }
        settings.extra = true;
        this.actSvc.getFinalizedAppData(this.tenant, this.subject_key, appType, this.APP_CONTEXT).subscribe(function (res) {
            settings.extra = true;
            if (res.result) {
                _this.logger.log(appType, 'configuration success');
                settings.extra = false;
                var out = res.result.filter(function (item) { return item.app_type === appType; }).map(function (opt) {
                    return opt[_this.APP_CONTEXT][0];
                });
                value[_this.APP_CONTEXT] = out[0];
                _this.settings.setValue('app_data_' + appType, value);
                _this.navCtrl.setRoot('LoginPage', {}, { animate: true, direction: 'forward' });
            }
            else {
                _this.logger.error('please setup bctx data for the product type' + appType);
            }
        }, function (err) {
            _this.logger.error(appType, err);
            settings.extra = false;
            _this.navCtrl.setRoot('LoginPage', {}, { animate: true, direction: 'forward' });
        });
    };
    __decorate([
        Object(__WEBPACK_IMPORTED_MODULE_0__angular_core__["ViewChild"])(__WEBPACK_IMPORTED_MODULE_2__modules_dynamic_form_containers_dynamic_form_dynamic_form_component__["a" /* DynamicFormComponent */]),
        __metadata("design:type", __WEBPACK_IMPORTED_MODULE_2__modules_dynamic_form_containers_dynamic_form_dynamic_form_component__["a" /* DynamicFormComponent */])
    ], ModuleConfigPage.prototype, "form", void 0);
    ModuleConfigPage = __decorate([
        Object(__WEBPACK_IMPORTED_MODULE_0__angular_core__["Component"])({
            selector: 'page-module-config',template:/*ion-inline-start:"/Users/shadeeka/office/dev/ncinga-spark-one-app/src/pages/module-config/module-config.html"*/'<!--\n  Generated template for the ModuleConfigPage page.\n\n  See http://ionicframework.com/docs/components/#navigation for more info on\n  Ionic pages and navigation.\n-->\n<ion-header>\n\n  <ion-navbar no-border-bottom color="ocean">\n    <ion-title>Module Configurations</ion-title>\n  </ion-navbar>\n\n</ion-header>\n\n\n<ion-content padding class="module-config">\n    <ion-grid no-padding class="form-wrapper">\n        <ion-row class="border-btm">\n            <ion-col>\n                <h4 class="input-heading">App Pre settings</h4>\n                <p>Please fill followings to complete installation</p>\n            </ion-col>\n        </ion-row>\n        <ion-row>\n            <ion-item class="orientation-item">\n                <ion-label>Orientation <span *ngIf="landscape" class="orientation-lbl">Landscape</span>\n                    <span class="orientation-lbl" *ngIf="!landscape">Portrait</span></ion-label>\n                <ion-toggle color="secondary" mode="ios" [(ngModel)]="landscape"></ion-toggle>\n            </ion-item>\n        </ion-row>\n        <ion-row>\n            <ion-col col-12 *ngFor="let app of preSettingsByApp">\n                <h4>{{app.app_name}} <small>({{subject_key}})</small></h4>\n                <dynamic-form\n                        [config]="app.configs"\n                        #form="dynamicForm"\n                        (submit)="submit($event, app.app_type, app)">\n                </dynamic-form>\n                <p [hidden]="!app.extra">Completing app setting up ...<ion-spinner name="ios-small"></ion-spinner></p>\n            </ion-col>\n        </ion-row>\n    </ion-grid>\n</ion-content>\n'/*ion-inline-end:"/Users/shadeeka/office/dev/ncinga-spark-one-app/src/pages/module-config/module-config.html"*/,
        }),
        __metadata("design:paramtypes", [__WEBPACK_IMPORTED_MODULE_1_ionic_angular__["m" /* NavController */], __WEBPACK_IMPORTED_MODULE_1_ionic_angular__["n" /* NavParams */],
            __WEBPACK_IMPORTED_MODULE_4_ngx_logger__["b" /* NGXLogger */],
            __WEBPACK_IMPORTED_MODULE_7__ionic_native_screen_orientation__["a" /* ScreenOrientation */],
            __WEBPACK_IMPORTED_MODULE_5__ncinga_sp_nsp_app_core_dist_cache_settings__["a" /* Settings */], __WEBPACK_IMPORTED_MODULE_6__providers_activation_service_activation_service__["a" /* ActivationService */]])
    ], ModuleConfigPage);
    return ModuleConfigPage;
}());

//# sourceMappingURL=module-config.js.map

/***/ })

});
//# sourceMappingURL=16.js.map