webpackJsonp([14],{

/***/ 1210:
/***/ (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__(14);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__settings__ = __webpack_require__(1462);
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__["i" /* IonicPageModule */].forChild(__WEBPACK_IMPORTED_MODULE_2__settings__["a" /* SettingsPage */]),
            ],
        })
    ], SettingsPageModule);
    return SettingsPageModule;
}());

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

/***/ }),

/***/ 1462:
/***/ (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__(14);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__modules_cloud_index__ = __webpack_require__(785);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_ngx_logger__ = __webpack_require__(7);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__providers_app_extractor_app_extractor__ = __webpack_require__(146);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__providers_activation_service_activation_service__ = __webpack_require__(142);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__app_env__ = __webpack_require__(786);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__ncinga_sp_nsp_app_core_dist__ = __webpack_require__(53);
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, appContext, 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.appContext = appContext;
        this.cacheSvc = cacheSvc;
        this.APP_MASTER_KEY = 'app_master';
        this.isUpdateAvailable = false;
    }
    SettingsPage.prototype.ionViewDidLoad = function () {
        this.mobile_os = this.platform.is('cordova');
    };
    /*
     * cordova check binary update
     * */
    SettingsPage.prototype.checkForUpdate = function () {
        var _this = this;
        var checking = this.loadingCtrl.create({
            content: 'Checking for update...'
        });
        checking.present();
        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();
        var apps_with_versions = this.appMasterSvc.getAllProductTypesWithVersion();
        if (JSON.stringify(apps_with_versions) === '{}') {
            this.logger.error('no product types found ');
            return;
        }
        this.actSvc.checkUpdateAvailability({
            'app_master_id': appMasterId,
            'version': apps_with_versions,
            '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 () {
        var _this = this;
        if (this.mobile_os && this.latestAppUpdateDetail['update_type'] === 'BINARY') {
            this.checkForUpdate(); // 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.actSvc.getAppConfig(this.latestAppUpdateDetail['app_master_id']).subscribe(function (response) {
                _this.logger.debug('app master download success: does nothing implement here');
                //noinspection TypeScriptUnresolvedFunction
                _this.settings.setValue(_this.APP_MASTER_KEY, response).then(function (res) {
                    // console.log('save app master : ', res);
                    _this.sendUpdateAck(response);
                    window.location.reload(true);
                });
            });
        }
    };
    /*
     * send acknowledgement details to backend
     * */
    SettingsPage.prototype.sendUpdateAck = function (updateDetails) {
        // TODO: acknowledge updates with product types
        this.actSvc.acknowledgeAgent([{}], 'update').subscribe(function (res) {
        });
    };
    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.loadingCtrl.create({
            content: 'Updating application...'
        });
        updating.present();
        this.deploy.download().then(function () { return _this.deploy.extract(); }).then(function () { return _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:"/Users/shadeeka/office/dev/ncinga-spark-one-app/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 2.0</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()">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:"/Users/shadeeka/office/dev/ncinga-spark-one-app/src/pages/settings/settings.html"*/,
        }),
        __metadata("design:paramtypes", [__WEBPACK_IMPORTED_MODULE_2__modules_cloud_index__["b" /* Deploy */],
            __WEBPACK_IMPORTED_MODULE_1_ionic_angular__["p" /* Platform */],
            __WEBPACK_IMPORTED_MODULE_1_ionic_angular__["m" /* NavController */],
            __WEBPACK_IMPORTED_MODULE_1_ionic_angular__["j" /* LoadingController */],
            __WEBPACK_IMPORTED_MODULE_1_ionic_angular__["s" /* 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__["j" /* Settings */],
            __WEBPACK_IMPORTED_MODULE_5__providers_activation_service_activation_service__["a" /* ActivationService */],
            __WEBPACK_IMPORTED_MODULE_7__ncinga_sp_nsp_app_core_dist__["e" /* AuthProvider */],
            __WEBPACK_IMPORTED_MODULE_7__ncinga_sp_nsp_app_core_dist__["c" /* ApplicationContext */], __WEBPACK_IMPORTED_MODULE_7__ncinga_sp_nsp_app_core_dist__["f" /* CacheService */]])
    ], SettingsPage);
    return SettingsPage;
}());

//# sourceMappingURL=settings.js.map

/***/ })

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