webpackJsonp([31],{

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

"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SettingsPageModule", function() { return SettingsPageModule; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__angular_core__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_ionic_angular__ = __webpack_require__(5);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__settings__ = __webpack_require__(1767);
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 SettingsPageModule = /** @class */ (function () {
    function SettingsPageModule() {
    }
    SettingsPageModule = __decorate([
        Object(__WEBPACK_IMPORTED_MODULE_0__angular_core__["NgModule"])({
            declarations: [
                __WEBPACK_IMPORTED_MODULE_2__settings__["a" /* SettingsPage */],
            ],
            imports: [
                __WEBPACK_IMPORTED_MODULE_1_ionic_angular__["j" /* IonicPageModule */].forChild(__WEBPACK_IMPORTED_MODULE_2__settings__["a" /* SettingsPage */]),
            ],
        })
    ], SettingsPageModule);
    return SettingsPageModule;
}());

//# sourceMappingURL=settings.module.js.map

/***/ }),

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

"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return SettingsPage; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__angular_core__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_ionic_angular__ = __webpack_require__(5);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__modules_cloud_index__ = __webpack_require__(358);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_ngx_logger__ = __webpack_require__(4);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__providers_app_extractor_app_extractor__ = __webpack_require__(141);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__providers_activation_service_activation_service__ = __webpack_require__(100);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__app_env__ = __webpack_require__(206);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__ncinga_sp_nsp_app_core_dist__ = __webpack_require__(7);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_8__ionic_native_splash_screen__ = __webpack_require__(205);
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 SettingsPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */
var SettingsPage = /** @class */ (function () {
    function SettingsPage(deploy, platform, navCtrl, loadingCtrl, toastCtrl, logger, appMasterSvc, settings, actSvc, authSvc, splashScreen, appContext, versionMgr, cacheSvc) {
        this.deploy = deploy;
        this.platform = platform;
        this.navCtrl = navCtrl;
        this.loadingCtrl = loadingCtrl;
        this.toastCtrl = toastCtrl;
        this.logger = logger;
        this.appMasterSvc = appMasterSvc;
        this.settings = settings;
        this.actSvc = actSvc;
        this.authSvc = authSvc;
        this.splashScreen = splashScreen;
        this.appContext = appContext;
        this.versionMgr = versionMgr;
        this.cacheSvc = cacheSvc;
        this.APP_MASTER_KEY = 'app_master';
        this.isUpdateAvailable = false;
        this.description = 'About app. Small description';
        this.version = '';
    }
    SettingsPage.prototype.ionViewDidLoad = function () {
        var _this = this;
        this.mobile_os = this.platform.is('cordova');
        this.settings.getValue('versions').then(function (res) {
            _this.apps_with_versions = res;
        });
        this.description = this.appMasterSvc.getAppDescription();
        this.version = this.versionMgr.getVersionNumber();
    };
    /*
     * cordova check binary update
     * */
    SettingsPage.prototype.checkForUpdate = function () {
        var _this = this;
        var checking = this.loadingCtrl.create({
            content: 'Checking for update...'
        });
        checking.present();
        var appid = this.appMasterSvc.getAppMasterId();
        this.deploy.channel = appid;
        this.deploy.check().then(function (snapshotAvailable) {
            checking.dismiss();
            if (!snapshotAvailable) {
                var toast = _this.toastCtrl.create({
                    message: 'No update available',
                    duration: 3000
                });
                toast.present();
            }
            else {
                _this.downloadAndInstall();
            }
        });
    };
    /*
     * check if updates available before doing anything
     * */
    SettingsPage.prototype.getUpdateDetails = function () {
        var _this = this;
        var appMasterId = this.appMasterSvc.getAppMasterId();
        // let appMasterId = '5b0b7914f22adf0001c6c29c';
        var currentSubject = this.appContext.getCurrentSubject();
        if (this.apps_with_versions && JSON.stringify(this.apps_with_versions) === '{}') {
            this.logger.error('no product types found ');
            return;
        }
        this.actSvc.checkUpdateAvailability({
            'app_master_id': appMasterId,
            'version': this.apps_with_versions,
            'binary': this.version,
            'subject': currentSubject.id,
            'channel_tag': __WEBPACK_IMPORTED_MODULE_6__app_env__["a" /* ENV */].mode
        }).subscribe(function (res) {
            _this.logger.debug(res);
            _this.newVersion = res['version_no'];
            _this.isUpdateAvailable = res['isUpdateAvailable'];
            _this.latestAppUpdateDetail = res;
            _this.logger.debug('newVersion : ' + _this.newVersion);
        });
    };
    SettingsPage.prototype.updateApp = function () {
        if (this.mobile_os && this.latestAppUpdateDetail['update_type'] === 'BINARY') {
            this.updateBinary(); // if this is a binary update and do it
        }
        else if (this.latestAppUpdateDetail['update_type'] === 'APP_MASTER') {
            // download app master config and save it in cache
            this.updateAppMaster();
        }
    };
    SettingsPage.prototype.updateBinary = function () {
        var _this = this;
        this.actSvc.getAppConfig(this.latestAppUpdateDetail['app_master_id']).subscribe(function (response) {
            _this.settings.setValue(_this.APP_MASTER_KEY, response).then(function (res) {
            });
            _this.checkForUpdate(); // if this is a binary update and do it
        });
    };
    SettingsPage.prototype.updateAppMaster = function () {
        var _this = this;
        this.actSvc.getAppConfig(this.latestAppUpdateDetail['app_master_id']).subscribe(function (response) {
            _this.logger.debug('app master download success: does nothing implement here');
            _this.updateVersions(response);
            //noinspection TypeScriptUnresolvedFunction
            _this.settings.setValue(_this.APP_MASTER_KEY, response).then(function (res) {
                // console.log('save app master : ', res);
                _this.sendUpdateAck(response);
                // this.deploy.load();
                _this.splashScreen.show();
                window.location.hash = '#/';
                window.location.reload(true);
            });
        });
    };
    SettingsPage.prototype.updateBinaryVersions = function (response) {
        for (var key in this.apps_with_versions) {
            if (this.apps_with_versions[key]) {
                this.apps_with_versions[key] = response['latest_version'];
            }
        }
        return this.settings.setValue('versions', this.apps_with_versions);
    };
    SettingsPage.prototype.updateVersions = function (response) {
        var ptypes = {};
        response.apps.forEach(function (item) {
            ptypes[item.product_type] = item.version;
        });
        this.apps_with_versions = ptypes;
        //noinspection TypeScriptUnresolvedFunction
        return this.settings.setValue('versions', ptypes);
    };
    /*
     * send acknowledgement details to backend
     * */
    SettingsPage.prototype.sendUpdateAck = function (updateDetails) {
        var _this = this;
        try {
            var newapps_1 = [];
            updateDetails.apps.forEach(function (item) {
                newapps_1.push({
                    app_id: item.app_id,
                    product_type: item.product_type,
                    version: item.version,
                    license_key: _this.actSvc.getLicenseKey(item.product_type)
                });
            });
            // TODO: acknowledge updates with product types
            this.actSvc.acknowledgeAgent(newapps_1, 'update').subscribe(function (res) {
            });
        }
        catch (e) {
            this.logger.error(e);
        }
    };
    SettingsPage.prototype.changeApp = function () {
        var _this = this;
        // TODO: clear all cache
        this.cacheSvc.deleteAll();
        this.actSvc.removeApp().then(function (res) {
            _this.navCtrl.setRoot('ActivationPage', {}, { animate: true, direction: 'back' });
        });
    };
    SettingsPage.prototype.downloadAndInstall = function () {
        var _this = this;
        var updating = this.toastCtrl.create({
            message: 'Updating application...',
            cssClass: 'bottomToast',
            position: 'top'
        });
        updating.present();
        this.deploy.download().then(function () { return _this.deploy.extract(); }).then(function () {
            _this.updateBinaryVersions(_this.latestAppUpdateDetail); // update versions
            _this.deploy.load();
        });
    };
    SettingsPage.prototype.clearCache = function () {
        this.cacheSvc.deleteAll();
        this.authSvc.logout();
        this.navCtrl.setRoot('LoginPage', null, { animate: true });
    };
    SettingsPage = __decorate([
        Object(__WEBPACK_IMPORTED_MODULE_0__angular_core__["Component"])({
            selector: 'page-settings',template:/*ion-inline-start:"/disk1/jenkins/workspace/ncinga_spark_installation_apk/src/pages/settings/settings.html"*/'<!--\n  Generated template for the SettingsPage 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 color="mheader">\n    <ion-title>Settings</ion-title>\n  </ion-navbar>\n\n</ion-header>\n\n\n<ion-content padding>\n    <ion-card>\n        <ion-card-content>\n            <ion-grid>\n                <ion-row>\n                    <ion-col col-3>\n                        <div class="image-wrapper">\n                            <img src="assets/imgs/app-icon.png">\n                        </div>\n                    </ion-col>\n                    <ion-col class="details-wrapper">\n                        <h5>nFactory</h5>\n                        <p class="version-label">Version {{version}}</p>\n                        <p>Phasellus ac efficitur risus. Fusce sodales, massa et dapibus iaculis, eros ex pharetra erat, at sagittis nisi arcu a mi. Vivamus in justo varius, semper arcu vitae, dapibus lectus.\n                        </p>\n                    </ion-col>\n                </ion-row>\n            </ion-grid>\n            </ion-card-content>\n    </ion-card>\n<ion-list class="update-action-list">\n    <ion-list-header><ion-icon name="phone-portrait"></ion-icon>System Update</ion-list-header>\n    <ion-item>\n        <h2>Licence KEY</h2>\n        <p>NVP-11-xxxx-xxxx-xxxx</p>\n    </ion-item>\n    <ion-item>\n        <h2>Check For updates</h2>\n        <h4 *ngIf="newVersion" class="new-version-msg"> New Version available <span class="version-no">{{newVersion}}</span></h4>\n        <p>By clicking this, you are agreeing for nFactory terms and conditions.</p>\n        <button ion-button color="mheader" item-end (click)="getUpdateDetails()">Check now</button>\n        <button *ngIf="isUpdateAvailable" ion-button color="mheader" item-end (click)="updateApp()">Update now</button>\n    </ion-item>\n    <ion-item>\n        <h2>Change app</h2>\n        <p>By clicking this, you can remove existing app and change into a different.</p>\n        <button ion-button color="mheader" item-end (click)="changeApp()" disabled>Change </button>\n    </ion-item>\n    <ion-item>\n        <h2>Clear App Data</h2>\n        <p>This will delete all saved data inside the app.</p>\n        <button ion-button color="mheader" item-end (click)="clearCache()">Clear Data</button>\n    </ion-item>\n</ion-list>\n</ion-content>\n<ion-footer>\n    <p class="copy-right">nCinga Innovations � All Rights recerved 2018</p>\n</ion-footer>\n'/*ion-inline-end:"/disk1/jenkins/workspace/ncinga_spark_installation_apk/src/pages/settings/settings.html"*/,
        }),
        __metadata("design:paramtypes", [__WEBPACK_IMPORTED_MODULE_2__modules_cloud_index__["b" /* Deploy */],
            __WEBPACK_IMPORTED_MODULE_1_ionic_angular__["r" /* Platform */],
            __WEBPACK_IMPORTED_MODULE_1_ionic_angular__["o" /* NavController */],
            __WEBPACK_IMPORTED_MODULE_1_ionic_angular__["k" /* LoadingController */],
            __WEBPACK_IMPORTED_MODULE_1_ionic_angular__["w" /* ToastController */],
            __WEBPACK_IMPORTED_MODULE_3_ngx_logger__["b" /* NGXLogger */],
            __WEBPACK_IMPORTED_MODULE_4__providers_app_extractor_app_extractor__["a" /* AppExtractorService */],
            __WEBPACK_IMPORTED_MODULE_7__ncinga_sp_nsp_app_core_dist__["o" /* Settings */],
            __WEBPACK_IMPORTED_MODULE_5__providers_activation_service_activation_service__["a" /* ActivationService */],
            __WEBPACK_IMPORTED_MODULE_7__ncinga_sp_nsp_app_core_dist__["f" /* AuthProvider */],
            __WEBPACK_IMPORTED_MODULE_8__ionic_native_splash_screen__["a" /* SplashScreen */],
            __WEBPACK_IMPORTED_MODULE_7__ncinga_sp_nsp_app_core_dist__["d" /* ApplicationContext */],
            __WEBPACK_IMPORTED_MODULE_7__ncinga_sp_nsp_app_core_dist__["p" /* VersionManager */],
            __WEBPACK_IMPORTED_MODULE_7__ncinga_sp_nsp_app_core_dist__["h" /* CacheService */]])
    ], SettingsPage);
    return SettingsPage;
}());

//# sourceMappingURL=settings.js.map

/***/ })

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