f0a8de648b910b8518da8057a00204c91d9a9681
[archive/20170607/tools/tic.git] / public / src / js / model / JobModel.js
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.1 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 define([
18     'jquery',
19     'lodash',
20     'js/util',
21     'js/logger',
22     'js/model/JobStatusModel'
23 ], function (
24     $,
25     _,
26     Util,
27     Logger,
28     JobStatusModel
29 ) {
30     'use strict';
31
32     var logger = Logger('model/JobModel.js');
33
34     // config
35     var AppConfig = null;
36
37     // define the downloadable status
38     var DOWNLOADABLE_STATUS = 'DONE';
39
40     // set the config information for the app
41     Util.getAppConfig().then(function (data) {
42         AppConfig = data;
43     });
44
45     var JobModel = function (paramObj) {
46         this.jobId = null;
47         this.jobStatus = null;
48         this.jobStatusText = null;
49         this.jobStatusClass = null;
50         this.jobImageName = null;
51         this.jobImageSize = null;
52         this.jobPid = null;
53         this.jobPath = null;
54         this.jobImagePath = null;
55         this.jobHasKsFile = false;
56         this.jobKs = null;
57         this.jobKsPath = null;
58         this.jobLogPath = null;
59         this.jobArch = null;
60         this.isDownload = false;
61
62         // for the href on a tag
63         this.jobAbsPath = null;
64         this.jobAbsImagePath = null;
65         this.jobAbsKsPath = null;
66         this.jobAbsLogPath = null;
67         this.jobUptime = null;
68
69         this.jobUserGroup = null;
70
71         this.init(paramObj);
72
73         return this;
74     };
75
76     JobModel.prototype.init = function (obj) {
77         logger.info('init: ' + JSON.stringify(obj));
78
79         this.setJobId(obj.job_id);
80         this.setJobAbsPath();
81         this.setJobPath();
82
83         this.setJobStatus(obj.job_status);
84         this.setJobImageName(obj.job_image_name);
85         this.setJobImageSize(obj.job_image_size);
86         this.setJobPid(obj.job_pid);
87
88         this.setJobHasKsFile(obj.job_hasksfile);
89         this.setJobKs(obj.job_ks);
90
91         this.setJobLogPath();
92         this.setJobArch(obj.job_arch);
93
94         this.setJobAbsLogPath();
95
96         this.setJobUptime(obj.job_uptime);
97
98         this.setJobUserGroup(obj.job_usergroup);
99     };
100
101     JobModel.prototype.getIsDownload = function () {
102         return this.isDownload;
103     };
104
105     JobModel.prototype.setIsDownload = function (value) {
106         this.isDownload = value || false;
107     };
108
109     JobModel.prototype.getJobUptime = function () {
110         return this.jobUptime;
111     };
112
113     JobModel.prototype.setJobUptime = function (value) {
114         this.jobUptime = value;
115     };
116
117     JobModel.prototype.getJobUserGroup = function () {
118         return this.jobUserGroup;
119     };
120
121     JobModel.prototype.setJobUserGroup = function (value) {
122         this.jobUserGroup = value;
123     };
124
125     JobModel.prototype.getJobLogPath = function () {
126         return this.jobLogPath;
127     };
128
129     JobModel.prototype.setJobLogPath = function () {
130         this.jobLogPath = this.getJobPath() + AppConfig.MIC.LOG;
131     };
132
133     JobModel.prototype.getJobArch = function () {
134         return this.jobArch;
135     };
136
137     JobModel.prototype.setJobArch = function (value) {
138         /**
139          * FIXME
140          *
141          * Confirm default value . armv7l right?
142          */
143         this.jobArch = value || 'armv7l';
144     };
145
146     JobModel.prototype.getJobAbsLogPath = function () {
147         return this.jobAbsLogPath;
148     };
149
150     JobModel.prototype.setJobAbsLogPath = function () {
151         this.jobAbsLogPath = this.getJobAbsPath() + AppConfig.MIC.LOG;
152     };
153
154     JobModel.prototype.getJobKsPath = function () {
155         return this.jobKsPath;
156     };
157
158     JobModel.prototype.setJobKsPath = function () {
159         this.jobKsPath = this.getJobPath() + this.getJobKs();
160     };
161
162     JobModel.prototype.getJobAbsKsPath = function () {
163         return this.jobAbsKsPath;
164     };
165
166     JobModel.prototype.setJobAbsKsPath = function () {
167         this.jobAbsKsPath = this.getJobAbsPath() + this.getJobKs();
168     };
169
170     JobModel.prototype.getJobHasKsFile = function () {
171         return this.jobHasKsFile;
172     };
173
174     JobModel.prototype.setJobHasKsFile = function (value) {
175         this.jobHasKsFile = value || false;
176     };
177
178     JobModel.prototype.getJobKs = function () {
179         return this.jobKs;
180     };
181
182     JobModel.prototype.setJobKs = function (value) {
183         this.jobKs = value || '';
184
185         this.setJobKsPath();
186         this.setJobAbsKsPath();
187     };
188
189     JobModel.prototype.getJobImagePath = function () {
190         return this.jobImagePath;
191     };
192
193     JobModel.prototype.setJobImagePath = function () {
194         this.jobImagePath = this.getJobPath() + this.getJobImageName();
195     };
196
197     JobModel.prototype.getJobImageSize = function () {
198         return this.jobImageSize;
199     };
200
201     JobModel.prototype.setJobImageSize = function (value) {
202         this.jobImageSize = value ? Util.bytesToSize(value) : '0KB';
203     };
204
205     JobModel.prototype.getJobPid = function () {
206         return this.jobPid;
207     };
208
209     JobModel.prototype.setJobPid = function (value) {
210         this.jobPid = value || null;
211     };
212
213     JobModel.prototype.getJobPath = function () {
214         return this.jobPath;
215     };
216
217     JobModel.prototype.setJobPath = function () {
218         this.jobPath = AppConfig.TIC_WEB.PATH + this.getJobId() + '/';
219     };
220
221     JobModel.prototype.getJobAbsImagePath = function () {
222         return this.jobAbsImagePath;
223     };
224
225     JobModel.prototype.setJobAbsImagePath = function () {
226         this.jobAbsImagePath = this.getJobAbsPath() + this.getJobImageName();
227     };
228
229     JobModel.prototype.getJobAbsPath = function () {
230         return this.jobAbsPath;
231     };
232
233     JobModel.prototype.setJobAbsPath = function () {
234         this.jobAbsPath = AppConfig.TIC_WEB.PATH_ABSTRACT + this.getJobId() + '/';
235     };
236
237     JobModel.prototype.getJobImageName = function () {
238         return this.jobImageName;
239     };
240
241     JobModel.prototype.setJobImageName = function (value) {
242         this.jobImageName = value || '-';
243
244         this.setJobImagePath();
245         this.setJobAbsImagePath();
246     };
247
248     JobModel.prototype.getJobStatusText = function () {
249         return this.jobStatusText;
250     };
251
252     JobModel.prototype.setJobStatusText = function (value) {
253         this.jobStatusText = value || '';
254     };
255
256     JobModel.prototype.getJobStatusClass = function (value) {
257         return this.jobStatusClass;
258     };
259
260     JobModel.prototype.setJobStatusClass = function (value) {
261         this.jobStatusClass = value || '';
262     };
263
264     JobModel.prototype.getJobStatus = function () {
265         return this.jobStatus;
266     };
267
268     JobModel.prototype.setJobStatus = function (status) {
269         var statusInfo, isDownloadable;
270
271         isDownloadable = false;
272         statusInfo = JobStatusModel.getStatusInfo(status);
273         /**
274          * statusInfo = {
275          *      value: 'READY',
276          *      text: 'Ready',
277          *      class: 'fa'
278          * }
279          */
280
281         this.jobStatus = statusInfo.value || '';
282         this.setJobStatusText(statusInfo.text);
283         this.setJobStatusClass(statusInfo.class);
284
285         if (this.getJobStatus() === DOWNLOADABLE_STATUS) {
286             isDownloadable = true;
287         }
288
289         this.setIsDownload(isDownloadable);
290     };
291
292     JobModel.prototype.getJobId = function () {
293         return this.jobId;
294     };
295
296     JobModel.prototype.setJobId = function (value) {
297         this.jobId = value || 0;
298     };
299
300     return JobModel;
301 });