-
Notifications
You must be signed in to change notification settings - Fork 1
/
shipments-app.js
65 lines (62 loc) · 2.32 KB
/
shipments-app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { Component, DefineMap, route, stacheRouteHelpers, value } from "can";
import {mockOrganizationsService} from "~/models/fixtures/organizations";
mockOrganizationsService();
import {mockShipmentsService} from "~/models/fixtures/shipments";
mockShipmentsService();
Component.extend({
tag: "shipments-app",
view: `
{{# if(componentToShow.isResolved) }}
{{componentToShow.value}}
{{/ if }}
`,
ViewModel: {
routeData: {
default() {
const observableRouteData = new DefineMap();
route.data = observableRouteData;
route.register("{page}", { page: "home" });
route.start();
return observableRouteData;
}
},
get componentToShow(){
if(!this.isLoggedIn) {
return steal.import("shipments-app/pages/login/login")
.then((module) => {
return new module.default({
viewModel: {
isLoggedIn: value.bind(this, "isLoggedIn")
}
});
});
}
return steal.import(`shipments-app/pages/${this.routeData.page}/${this.routeData.page}`)
.then((module) => {
switch(this.routeData.page) {
case "home":
return new module.default({
viewModel: {
logout: this.logout.bind(this)
}
});
case "organizations":
case "shipments":
return new module.default({
viewModel: {
logout: this.logout.bind(this)
}
});
default:
var page404 = document.createElement("h2");
page404.innerHTML = "Page Missing";
return page404;
}
});
},
isLoggedIn: { default: false, type: "boolean" },
logout() {
this.isLoggedIn = false;
}
}
});