From 108131e7807c77c6ed4ee297b0918da54b4d6e48 Mon Sep 17 00:00:00 2001 From: Titogelo Date: Mon, 13 Feb 2017 15:32:42 +0100 Subject: [PATCH] #277 register and login user, create scenario --- src/main/webapp/src/assets/i18n/en.json | 1 + .../components/activity/activity.resource.js | 25 ++++++++++-- .../components/activity/activity.service.js | 39 ++++++++++++++++++- .../src/components/common/property.service.js | 3 +- .../components/home/game.edit.controller.js | 18 +++++++++ .../components/home/new.activity.modal.html | 6 +++ 6 files changed, 87 insertions(+), 5 deletions(-) diff --git a/src/main/webapp/src/assets/i18n/en.json b/src/main/webapp/src/assets/i18n/en.json index 4926aa2..f5787de 100644 --- a/src/main/webapp/src/assets/i18n/en.json +++ b/src/main/webapp/src/assets/i18n/en.json @@ -103,6 +103,7 @@ "title-activity": "Title:", "type-activity": "Type:", "video-activity": "Video link:", + "mobile-data-collection": "Mobile?", "google-activity": "Google resource link:", "description-activity": "Description:", "roles-activity": "Roles:", diff --git a/src/main/webapp/src/components/activity/activity.resource.js b/src/main/webapp/src/components/activity/activity.resource.js index 0291e7a..1e850e6 100644 --- a/src/main/webapp/src/components/activity/activity.resource.js +++ b/src/main/webapp/src/components/activity/activity.resource.js @@ -1,5 +1,4 @@ angular.module('DojoIBL') - .factory('Activity', function ActivityFactory($resource, $http, config) { return $resource(config.server+'/rest/generalItems', {}, { getActivities: { @@ -52,6 +51,26 @@ angular.module('DojoIBL') isArray: false, url: config.server + '/rest/generalItems/pictureUrl/gameId/:gameId/generalItem/:itemId/:key' } + + }) + ; + }) + .factory('ML4WUser', function ScenarioFactory($resource, $http, config) { + return $resource(config.mobile_data_collection+'/users/register/', {}, { + 'login': { + method: 'POST', + isArray: false, + url: config.mobile_data_collection + '/users/login' + } + }); + }) + .factory('ML4WScenario', function ScenarioFactory($resource, $http, config) { + return $resource(config.mobile_data_collection+'/scenarios/', {}, { + 'create': { + method: 'POST', + isArray: false, + url: config.mobile_data_collection + '/scenarios/' + } }); - } -); \ No newline at end of file + }) +; \ No newline at end of file diff --git a/src/main/webapp/src/components/activity/activity.service.js b/src/main/webapp/src/components/activity/activity.service.js index ad8bea4..fbaf007 100644 --- a/src/main/webapp/src/components/activity/activity.service.js +++ b/src/main/webapp/src/components/activity/activity.service.js @@ -1,6 +1,6 @@ angular.module('DojoIBL') - .service('ActivityService', function ($q, Activity, CacheFactory) { + .service('ActivityService', function ($q, Activity, CacheFactory, ML4WUser, ML4WScenario) { CacheFactory('activitiesCache', { maxAge: 24 * 60 * 60 * 1000, // Items added to this cache expire after 1 day @@ -227,6 +227,43 @@ angular.module('DojoIBL') removeCachedActivity: function(){ var dataCache = CacheFactory.get('activitiesTempCache'); dataCache.remove("cachedActivity"); + }, + createML4WScenario: function(title, token){ + var scenario = { + title: title, + description: "Angel", + token: token, + screenData: [{}] + }; + + var newScenario = new ML4WScenario(scenario); + return newScenario.$save(); + }, + registerML4WUser: function(user, pass){ + var user = { + firstname: "Angel", + lastname: "Angel", + email: "angel.suarez@ou.nl", + username: user, + password: pass + }; + + var newUser = new ML4WUser(user); + return newUser.$save(); + }, + loginML4WUser: function(user, pass){ + var deferred = $q.defer(); + + var user = { + username: user, + password: pass + }; + + ML4WUser.login(user).$promise.then(function (data) { + deferred.resolve(data); + }); + + return deferred.promise; } } }) diff --git a/src/main/webapp/src/components/common/property.service.js b/src/main/webapp/src/components/common/property.service.js index 12c6eb1..67dda19 100644 --- a/src/main/webapp/src/components/common/property.service.js +++ b/src/main/webapp/src/components/common/property.service.js @@ -3,7 +3,8 @@ angular.module('DojoIBL') .constant('config', { //"server": "http://dojo-ibl.appspot.com" //"server": "http://localhost:8888" - "server": "" + "server": "", + "mobile_data_collection": "http://celtest1.lnu.se:3333" } ); \ No newline at end of file diff --git a/src/main/webapp/src/components/home/game.edit.controller.js b/src/main/webapp/src/components/home/game.edit.controller.js index 8136c82..843402f 100644 --- a/src/main/webapp/src/components/home/game.edit.controller.js +++ b/src/main/webapp/src/components/home/game.edit.controller.js @@ -646,6 +646,16 @@ angular.module('DojoIBL') }); }); + + if(result.mobile){ + ActivityService.registerML4WUser($scope.me.localId, $scope.me.localId+"password"); + ActivityService.loginML4WUser($scope.me.localId, $scope.me.localId+"password").then(function(data){ + + ActivityService.createML4WScenario("pruebas", data.token); + }); + } + + console.log("Modal Accepted!!!"); //if (angular.isDefined(stop)) { // $interval.cancel(stop); @@ -675,6 +685,14 @@ angular.module('DojoIBL') console.log(result); + if(result.mobile){ + ActivityService.registerML4WUser(angular.lowercase($scope.me.localId), $scope.me.localId+"password"); + ActivityService.loginML4WUser(angular.lowercase($scope.me.localId), $scope.me.localId+"password").then(function(data){ + + ActivityService.createML4WScenario("pruebas", data.token); + }); + } + ActivityService.newActivity(result).then(function(data){ ActivityService.refreshActivity(data.id, data.gameId); }); diff --git a/src/main/webapp/src/components/home/new.activity.modal.html b/src/main/webapp/src/components/home/new.activity.modal.html index 3fc3ca8..c591a9e 100644 --- a/src/main/webapp/src/components/home/new.activity.modal.html +++ b/src/main/webapp/src/components/home/new.activity.modal.html @@ -24,6 +24,12 @@ +
+ +
+ +
+