forked from akoumi01/epl363-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sTeamCollaborationPlatformApp.js
405 lines (393 loc) · 16.1 KB
/
sTeamCollaborationPlatformApp.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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
/**
* @class angular_module.sTeamCollaborationPlatformApp
* @memberOf angular_module
* @description sTeamCollaborationPlatformApp module is the main module of the
* sTeam collaboration platform website. Through its controllers,
* all the platform views are handled and being exchanged.
* 'ngRoute'(handles the routing of the website), 'steam', and
* 'LocalStorageModule'(handles the local storage of the browser)
* are the Angular Js modules that are included in the angularjs
* module.
*/
var app=angular.module('sTeamCollaborationPlatformApp', ['ngRoute','steam','LocalStorageModule']);
app.config(['$routeProvider', '$locationProvider', function ($routeProvider,$locationProvider) {
$routeProvider.when('/', {
templateUrl: 'views/index.html',
controller: 'IndexCtrl',
requireLogin: false
})
.when('/index', {
templateUrl: 'views/index.html',
controller: 'IndexCtrl',
requireLogin: false
})
.when('/index.html', {
templateUrl: 'views/index.html',
controller: 'IndexCtrl',
requireLogin: false
}).when('/notifications', {
templateUrl: 'views/notifications.html',
controller: 'notificationsCtrl',
requireLogin: true
})
.when('/editProfile', {
templateUrl: 'views/editProfile.html',
controller: 'editProfileCtrl',
requireLogin: true
})
.when('/messages', {
templateUrl: 'views/messages.html',
controller: 'messagesCtrl',
requireLogin: true
})
.when('/adminPanel', {
templateUrl: 'views/adminPanel.html',
controller: 'adminPanelCtrl',
requireLogin: true
})
.when("/home/:paramiters*",{
templateUrl: 'views/home.html',
controller: 'homeCtrl',
requireLogin: true
})
.when("/home/",{
templateUrl: 'views/home.html',
controller: 'homeCtrl',
requireLogin: true
})
.when("/home",{
templateUrl: 'views/home.html',
controller: 'homeCtrl',
requireLogin: true
})
.when("/error",{
templateUrl: 'views/error.html',
controller: 'errorCtrl',
requireLogin: true
}).otherwise({ redirectTo: '/error' });
}]);
app.run(['$rootScope', '$location', 'steam', function ($rootScope, $location,steam ) {
$rootScope.$on('$routeChangeStart', function (event,next,current) {
if (!steam.loginp()&& next.requireLogin) {
event.preventDefault();
$location.path('/');
}else if(steam.loginp()&& !next.requireLogin){
event.preventDefault();
$location.path('/notifications');
}
});
}]);
/**
* @function IndexCtrl
* @memberOf angular_module.sTeamCollaborationPlatformApp
* @description IndexCtrl contains the log in function. In future updates of the
* website the sing up functionalities will be added
*/
app.controller('IndexCtrl', ['$scope','steam','$location',"$window",function ($scope,steam,$location,$window) {
/**
* @name $scope.logIn
* @function
* @memberOf angular_module.sTeamCollaborationPlatformApp.IndexCtrl
* @description Initially it creates a JQuery handler for Log in button
* and using a Bootstrap property the change of the button
* is being changed to the Loading state. Next, by using
* the steam.login function, the nickname and password
* information are verified and log in function is carried
* out. Then is server response is being handled, if login
* is successful then the user is redirected to
* notification Page. If login fails an error massage is
* displayed.
*/
$scope.logIn=function(){
var $btn = $("#btnSignIn");
$btn.button('loading');
steam.login($scope.userSignIn,$scope.signInpwd).then(function(response) {
$btn.button('reset');
$('#signIn').modal('hide');
$location.path('/notifications');
$window.location.reload();
}).catch(function(e){
$btn.button('reset');
$('#signIn').modal('hide');
alert("Wrong username or password");
})
}
}]);
/**
* @function errorCtrl
* @memberOf angular_module.sTeamCollaborationPlatformApp
* @description The errorCtrl controller handles the error Page
*/
app.controller('errorCtrl', ['$scope', function ($scope) {
}]);
/**
* @function editProfileCtrl
* @memberOf angular_module.sTeamCollaborationPlatformApp
* @description The editProfileCtrl controller handles the Edit Profile Page
* View (prototype). In future updates of the website the edit
* Profile functions will be added.
*/
app.controller('editProfileCtrl', ['$scope', function ($scope) {
}]);
/**
* @function notificationsCtrl
* @memberOf angular_module.sTeamCollaborationPlatformApp
* @description The notificationsCtrl handles the notifications View
* (prototype). In future updates of the website the notifications
* functions will be added.
*/
app.controller('notificationsCtrl', ['$scope', function ($scope) {
}]);
/**
* @function messagesCtrl
* @memberOf angular_module.sTeamCollaborationPlatformApp
* @description The messagesCtrl handles the messaging View (Prototype). In
* future updates of the website the messaging functionalities will
* be added.
*/
app.controller('messagesCtrl', ['$scope', function ($scope) {
}]);
/**
* @function adminPanelCtrl
* @memberOf angular_module.sTeamCollaborationPlatformApp
* @description The adminPanelCtrl handles the Admin Panel functionalities
* (Prototype). In future updates of the website the Admin Panel
* functionalities will be added.
*/
app.controller('adminPanelCtrl', ['$scope', function ($scope) {
}]);
/**
* @function homeCtrl
* @memberOf angular_module.sTeamCollaborationPlatformApp
* @description Through the homeCtrl the user can navigate through the rooms of
* the platform. It also provides functions for creating new text
* document, updating text document, creating new room.
*/
app.controller('homeCtrl', ['$scope','$http','$routeParams','$location','steam','localStorageService',"$window",function ($scope,$http,$routeParams,$location,steam,localStorageService,$window) {
$scope.myUrl='http://dev-back1.techgrind.asia/scripts/rest.pike?request=/home/'+$routeParams.paramiters;
var userDetails=steam.user();
$('#loadingBarModal').modal('show');
/**
* @name $scope.saveText
* @function
* @memberOf angular_module.sTeamCollaborationPlatformApp.homeCtrl
* @description It creates a JQuery handler for Save Text Document button.
* Using a Bootstrap property the state of the button is being
* changed to Loading state. Next, by using JSON.stringify
* function the text is transformed to JSON object with the
* following form { content:text}(text that needs to be
* stored). Also the request url is being prepared by using the
* route parameters and is being sent via steam.post(request
* url, {content:text}) to the server. According to the server
* response, the corresponding messages appear. *
*/
$scope.saveText=function() {
var $btn = $("#btnSavaTextDocument");
$btn.button('loading');
var text=document.getElementById('saveTextContent').value;
var data = JSON.stringify( { content:text});
var request=/home/+$routeParams.paramiters;
steam.post(request, data).then(function(response) {
$btn.button('reset')
alert("The document was saved successfully.");
}).catch(function(e){
$btn.button('reset');
alert("Error while saving the file");
});
}
/**
* @name $scope.createNewTextFile
* @function
* @memberOf angular_module.sTeamCollaborationPlatformApp.homeCtrl
* @description Function createNewTextFile, creates a JQuery handler for
* create New Text File button. Using a Bootstrap property the
* state of the button is being changed to Loading state. Next,
* by using JSON.stringify function, the text is transformed to
* JSON object with the following form { content:
* newtxtContent, type: "Document" }. Also the request url is
* being prepared by using the route parameters and is being
* sent via steam.put(request url, { content: newtxtContent,
* type: "Document" }) to the server. According to the server
* response, the corresponding messages appear.
*/
$scope.createNewTextFile=function(){
var $btn = $("#btnSavaNewTextDocument");
$btn.button('loading');
var data = JSON.stringify({content:$scope.newtxtContent,name:$scope.newtxtFileName, type:"Document" });
var request="/home/"+$routeParams.paramiters+"/"+$scope.newtxtFileName;
steam.put(request, {content:$scope.newtxtContent,name:$scope.newtxtFileName, type:"Document" }).then(function(response) {
$btn.button('reset');
$('#createNewTextDocumentModal').modal('hide');
alert("The file was successfully created.");
// $window.location.reload();
}).catch(function(e){
$btn.button('reset');
alert("Error while creating the file");
});
}
/**
* @name $scope.createRoom
* @function
* @memberOf angular_module.sTeamCollaborationPlatformApp.homeCtrl
* @description Function createRoom, creates a JQuery handler for create New
* Room button. Using a Bootstrap property the state of the
* button is being changed to Loading state. Next, by using
* JSON.stringify function, ({ type: "Room" }) is being
* transformed to JSON sting. Also the request url is being
* prepared by using the route parameters (/home/
* $routeParams.paramiters/roomName”) and there being sent via
* steam.put(request url, { type: "Room" }) to the server.
* According to the server response, the corresponding messages
* appear.
*/
$scope.createRoom=function(){
var $btn = $("#btnCreateRoom");
$btn.button('loading');
var data = JSON.stringify({ name:$scope.roomName,type:"Room" });
var request="/home/"+$routeParams.paramiters+"/"+$scope.roomName;
steam.put(request,data).then(function(response) {
$btn.button('reset');
$('#createRoomModal').modal('hide');
alert("The room was successfully created.");
// $window.location.reload();
}).catch(function(e){
$btn.button('reset');
alert("Error while creating the room");
});
}
$scope.WebUrl = "http://dev-back1.techgrind.asia";
if($routeParams.paramiters==null){
$scope.RestQuery='/home/';
}else{
$scope.RestQuery='/home/'+$routeParams.paramiters;
}
steam.get($scope.RestQuery).then(function(response) {
if(response.error!=null){
$location.path('/error');
}else{
$scope.Data = response;
if (angular.isArray(response.object)) {
$scope.objects = response.object;
$scope.Dtype="room";
} else {
$scope.Dtype="doc";
$scope.objects = [response.object];
}
if (angular.isArray(response.inventory)) {
$scope.inventory = response.inventory;
} else {
$scope.inventory = [response.inventory];
}
$scope.createPathForNavigation();
$('#loadingBarModal').modal('hide');
}
}).catch(function(e){
$('#loadingBarModal').modal('hide');
$location.path('/error');
$window.location.reload();
});
/**
* @name $scope.createPathForNavigation
* @function
* @memberOf angular_module.sTeamCollaborationPlatformApp.homeCtrl
* @description The purpose of the createNavPath function, is to create the
* navigation pane content path. This is done by using the
* route parameters (if they exist) to get the room or document
* names that the user has visited. For each room or document
* names the proper url is being created and stored. For each
* room that the user has visited a JSON object (containing the
* name of the room or document and their path) is created and
* inserted in the scope array.
*
*/
$scope.createPathForNavigation=function() {
var path=$routeParams.paramiters;
if(path!=null){
var indexs=[];
for (i = 0; i < path.length; i++) {
if(path.charAt(i)==='/')
indexs.push(i);
}
var name=path.split('/');
var paths=[];
paths.push({name:'home',url:'/home'});
var i=0;
for (i = 0; i < indexs.length; i++) {
paths.push({name:name[i],url:'/home/'+path.substring(0,indexs[i])});
}
paths.push({name:name[i],url:'/home/'+path});
$scope.paths=paths;
}else{
$scope.paths=[{name:'home',url:'/home'}];
}
}
/**
* @name $scope.isHome
* @function
* @memberOf angular_module.sTeamCollaborationPlatformApp.homeCtrl
* @description he isHome function returns true if the user is in the root
* Room. This function is used to present the buttons that
* allow the user to create new text Document (a text document
* @returns {boolean} if the user is in the root Room
*
*/
$scope.isHome=function(){
return ($routeParams.paramiters==undefined);
}
}]);
/**
* @function navController
* @memberOf angular_module.sTeamCollaborationPlatformApp
* @description The navController controls the navigation bar. It displays and
* hides the menu elements accordingly, depending if the user is
* login the platform or not.
*/
app.controller('navController', ['$scope', '$location','steam',function ($scope,$location,steam) {
/**
* @name $scope.setClass
* @function
* @memberOf angular_module.sTeamCollaborationPlatformApp.navController
* @description The setClass function is used for setting the class of a
* menu item in active if the proportionate view is selected.. *
* @param {string}
* The url of the menu item Description of parameter
* @returns {string} Return active if menu item path is same with the active
* url.
*/
$scope.setClass = function(path) {
if ($location.path().substr(0, path.length) == path) {
return "active"
}else{
return ""
}
}
/**
* @name $scope.logOut
* @function
* @memberOf angular_module.sTeamCollaborationPlatformApp.navController
* @description The logout function is used for the logging off
* functionality. It calls steam.logout function of steam
* module that is responsible for the user log off. *
*/
$scope.logOut=function(){
steam.logout();
}
/**
* @name $scope.isLogOut
* @function
* @memberOf angular_module.sTeamCollaborationPlatformApp.navController
* @description isLogOut function returns true if the user is log off
* the platform and false if the user logged in the
* platform. It is used for displaying and hiding menu
* elements of the menu bar accordingly, depending if the
* user is login the platform or not. *
*
* @returns {boolean} Returns true if the user is logged out from the
* platform
*/
$scope.isLogOut=function(){
if(steam.loginp()==null||!steam.loginp()){
return true;
}else return false;
}
}]);