-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOjetLab.txt
173 lines (115 loc) · 4.03 KB
/
OjetLab.txt
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
Objective:
Creating and running the OJET project
Analysing the folder structure
Create OJET project with navdrawer template
=> ojet create firstwebapp --template=navdrawer
Objective:
To understand data binding using knockout observables in OJET environment
Reference:
https://knockoutjs.com/documentation/textinput-binding.html
https://knockoutjs.com/documentation/value-binding.html
HTML: dashboard.html
<div>
<h6>Name : <input data-bind="textInput:name"> </h6>
<h6>Age : <input data-bind="textInput:age"> </h6>
<hr>
<h3>Your name is <span data-bind="text:name"> </span> and age is <span data-bind="text:age"> </span><h3>
</div>
JS: dashboard.js
// Observables for name and age
self.name = ko.observable("Kane");
self.age = ko.observable("26");
Does it work as expected?
What's the solution?
---------------------------------------
Objective:
To understand data binding using knockout observableArray in OJET environment
To understand the basics of using OJET components
HTML: dashboard.html
<h3>Please follow the statistics</h3>
<oj-chart type = "pie" series ="[[datasource]]">
</oj-chart>
JS: dashboard.js
//Observable array for data
var data = [
{name:"Pedestrians", items:[42]},
{name:"Vehicles", items:[82]},
{name:"Bicycles", items:[20]},
{name:"Busses", items:[76]},
{name:"Trains", items:[31]}
];
self.datasource = ko.observableArray(data);
Observe the browser, is the chart being displayed?
To resolve:
Add ojs/ojchart to the list of module requirements
----------------------------------
Objective:
To understand the technique for loading data from an external file
HTML: dashboard.html
Add the following to the existing code:
<h3>Your time should be distributed the following way</h3>
<oj-chart type = "pie" series ="[[datasource2]]">
</oj-chart>
Create a json file called data/data.json in js folder with following data:
[
{"name":"Work", "items":[8]},
{"name":"Play", "items":[3]},
{"name":"Eat", "items":[2]},
{"name":"Homework", "items":[3]},
{"name":"Exercise", "items":[1]},
{"name":"Sleep", "items":[6]},
{"name":"Netflix", "items":[1]}
]
Then prettify the file for a neat JSON format
PS: JSON file needs the keys to be in quotes
JS: dashboard.js
Add the code:
var data2 = JSON.parse(file);
self.datasource2 = ko.observableArray(data2);
Add the text reference for file
text!data/data.json -> in module requirements, text protocol/plugin from Require JS
file -> in the function parameters
Note that the order should be maintained
Please create a bar and pie component side by side horizontally!!
-------------------------------------------------
Objective:
Understanding and exploring the appController.js, main.js and router configuration
Creating new modules
Create employees.html in js/views
<div class="oj-hybrid-padding">
<h1>Employees</h1>
</div>
Create employees.js in js/viewModels
PS: It's basically a Require JS module
define(['accUtils', 'knockout', 'jquery'],
function(accUtils, ko, $) {
function EmployeesViewModel() {
}
return EmployeesViewModel;
}
);
Hook-up the view-viewModel to the application in appController.js
Add the following to navData:
{ path: 'employees', detail: { label: 'Employees', iconClass: 'oj-ux-ico-information-s' } },
Test with a simple ko observable
employees.html
<div class="oj-hybrid-padding">
<h1>Employees</h1>
<div>
<h6>Name : <input data-bind="textInput:name"> </h6>
<hr>
<h3>Your name is <span data-bind="text:name"> </span><h3>
</div>
</div>
employees.js
define(['accUtils', 'knockout', 'jquery'],
function(accUtils, ko, $) {
function EmployeesViewModel() {
var self = this;
self.name = ko.observable("Raj");
}
return EmployeesViewModel;
}
);
A module called "employees" is created
---------------------------------------------------------