68 lines
2.9 KiB
JavaScript
68 lines
2.9 KiB
JavaScript
"use strict";
|
|
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);
|
|
};
|
|
var core_1 = require("@angular/core");
|
|
var data_service_1 = require("./../../services/data.service");
|
|
var IntervalObservable_1 = require("rxjs/observable/IntervalObservable");
|
|
var user_class_1 = require("./../../classes/user.class");
|
|
var router_1 = require("@angular/router");
|
|
var UserComponent = (function () {
|
|
function UserComponent(route, data) {
|
|
this.route = route;
|
|
this.data = data;
|
|
this.loading = true;
|
|
this.error = false;
|
|
this.name = "Loading";
|
|
this.id = 0;
|
|
this.user = new user_class_1.User(0, "Loading", "Loading", "Loading");
|
|
}
|
|
UserComponent.prototype.getUser = function (id) {
|
|
var _this = this;
|
|
this.data.load().then(function () {
|
|
_this.data
|
|
.user(id)
|
|
.subscribe(function (b) {
|
|
var status = b.status_code;
|
|
if (status != 200 && b.data.length != 1) {
|
|
_this.loading = false;
|
|
_this.error = true;
|
|
}
|
|
else {
|
|
_this.user = user_class_1.User.toUser(b.data[0]);
|
|
_this.name = _this.user.name;
|
|
_this.loading = false;
|
|
}
|
|
});
|
|
});
|
|
};
|
|
UserComponent.prototype.ngOnInit = function () {
|
|
var _this = this;
|
|
this.id = this.route.snapshot.params['id'];
|
|
this.getUser(this.id);
|
|
this.subscription = IntervalObservable_1.IntervalObservable.create(5000).subscribe(function () {
|
|
console.log("Reloading data...");
|
|
_this.getUser(_this.id);
|
|
});
|
|
};
|
|
UserComponent.prototype.ngOnDestroy = function () {
|
|
this.subscription.unsubscribe();
|
|
};
|
|
return UserComponent;
|
|
}());
|
|
UserComponent = __decorate([
|
|
core_1.Component({
|
|
selector: 'app-user',
|
|
templateUrl: './user.component.html',
|
|
styleUrls: ['./user.component.css']
|
|
}),
|
|
__metadata("design:paramtypes", [router_1.ActivatedRoute, data_service_1.DataService])
|
|
], UserComponent);
|
|
exports.UserComponent = UserComponent;
|
|
//# sourceMappingURL=user.component.js.map
|