tfabrica
Version:
library for TFabrica - TechSol
108 lines • 5.11 kB
JavaScript
;
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);
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var http_1 = require("@angular/http");
require("rxjs/Rx");
var rxjs_1 = require("rxjs");
var tfabrica_usermenu_model_1 = require("../models/tfabrica.usermenu.model");
var tfabrica_usermenu_property_model_1 = require("../models/tfabrica.usermenu.property.model");
var tfabrica_shared_service_1 = require("../main/tfabrica.shared.service");
var TfabricaUserMenuService = (function () {
function TfabricaUserMenuService(http, tfabricaSharedService) {
this.http = http;
this.tfabricaSharedService = tfabricaSharedService;
this.menuUrl = "/api/Menu/UserMenu";
}
TfabricaUserMenuService.prototype.menu = function () {
//console.log("Start call service: " + this.menuUrl);
var actThis = this;
this.menuUrl = this.tfabricaSharedService.appSettings.userMenuApiUrl;
this.menuUrl = this.tfabricaSharedService.appSettings.getuserMenuApiUrl();
var userData = this.tfabricaSharedService.getUser();
var bodyString = {
"Username": userData.username,
"App": this.tfabricaSharedService.appSettings.appName,
"Token": userData.token
};
var headers = new http_1.Headers({ 'Content-Type': 'application/json' }); // ... Set content type to JSON
var options = new http_1.RequestOptions({ headers: headers }); // Create a request option
return this.http.post(this.menuUrl, bodyString, options) // ...using post request
.map(function (res) {
var response = res.json();
console.log(response);
var menus = actThis.convertResponseToUserMenu(response.menu);
//console.log(menus);
return menus;
}) // ...and calling .json() on the response to return data
.catch(function (error) { return rxjs_1.Observable.throw(error.json().error || 'Server error'); }); //...errors if any
};
TfabricaUserMenuService.prototype.convertResponseToUserMenu = function (res) {
//console.log("Start convertResponseToUserMenu");
//console.log(res);
var actThis = this;
var menus = Array();
res.forEach(function (entry) {
menus.push(actThis.convertSingleVoice(entry, undefined));
});
//console.log("End convertResponseToUserMenu -> menu:");
console.log(menus);
return menus;
};
TfabricaUserMenuService.prototype.convertSingleVoice = function (entry, father) {
console.log("Start convertSingleVoice with entry:");
console.log(entry);
var actThis = this;
//console.log("Create new Voice:");
var newVoice = new tfabrica_usermenu_model_1.TfabricaUserMenu();
newVoice.level = entry.Level;
newVoice.title = entry.Title;
newVoice.subTitle = entry.SubTitle;
newVoice.levelClass = "sidenav-level-" + (8 - entry.Level);
newVoice.isOpen = false;
newVoice.subMenu = Array();
newVoice.path = entry.Path;
newVoice.properties = Array();
try {
entry.Properties.forEach(function (property) {
var newProp = new tfabrica_usermenu_property_model_1.TfabricaUserMenuProperty();
newProp.key = property.Key;
newProp.value = property.Value;
newVoice.properties.push(newProp);
});
}
catch (Err) {
}
//console.log(newVoice);
try {
entry.SubMenu.forEach(function (subVoice) {
actThis.convertSingleVoice(subVoice, newVoice);
});
}
catch (Err) {
}
if (father != undefined) {
father.subMenu.push(newVoice);
return father;
}
else {
return newVoice;
}
};
return TfabricaUserMenuService;
}());
TfabricaUserMenuService = __decorate([
core_1.Injectable(),
__metadata("design:paramtypes", [http_1.Http,
tfabrica_shared_service_1.TfabricaSharedService])
], TfabricaUserMenuService);
exports.TfabricaUserMenuService = TfabricaUserMenuService;
//# sourceMappingURL=tfabrica.usermenu.service.js.map