Skip to content

Commit

Permalink
#277 register and login user, create scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
Titogelo committed Feb 13, 2017
1 parent b73015e commit 108131e
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/main/webapp/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:",
Expand Down
25 changes: 22 additions & 3 deletions src/main/webapp/src/components/activity/activity.resource.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
angular.module('DojoIBL')

.factory('Activity', function ActivityFactory($resource, $http, config) {
return $resource(config.server+'/rest/generalItems', {}, {
getActivities: {
Expand Down Expand Up @@ -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/'
}
});
}
);
})
;
39 changes: 38 additions & 1 deletion src/main/webapp/src/components/activity/activity.service.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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: "[email protected]",
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;
}
}
})
Expand Down
3 changes: 2 additions & 1 deletion src/main/webapp/src/components/common/property.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

);
18 changes: 18 additions & 0 deletions src/main/webapp/src/components/home/game.edit.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
Expand Down
6 changes: 6 additions & 0 deletions src/main/webapp/src/components/home/new.activity.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ <h4 ng-if="!activity.id" class="modal-title">Create activity</h4>
</select>
</div>
</div>
<div class="form-group" ng-show="activity.type == 'org.celstec.arlearn2.beans.generalItem.ScanTag'">
<label class="col-sm-3 control-label">{{ 'dibl.inquiry.new-edit.mobile-data-collection' | translate }}</label>
<div class="col-sm-9" >
<input icheck type="checkbox" ng-model="activity.mobile">
</div>
</div>
<div class="form-group" ng-show="activity.type == 'org.celstec.arlearn2.beans.generalItem.VideoObject'">
<label class="col-sm-3 control-label">{{ 'dibl.inquiry.new-edit.video-activity' | translate }}</label>
<div class="col-sm-9" >
Expand Down

0 comments on commit 108131e

Please sign in to comment.