Skip to content

Commit

Permalink
Log InputCode success activity (see #24)
Browse files Browse the repository at this point in the history
  • Loading branch information
miclaus committed Jul 18, 2016
1 parent f9945dc commit 70e6984
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
1 change: 1 addition & 0 deletions app/controllers/ActivityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function PushActivity ($mobidulCode)
foreach ($activities as $aIx => $activityData) {
$activity = new Activity;
$activity->code = $mobidulCode;
$activity->user = Auth::id();
$activity->type = $activityData->type;
$activity->name = $activityData->name;
$activity->payload = json_encode($activityData->payload);
Expand Down
6 changes: 3 additions & 3 deletions app/start/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@

App::error(function(Exception $exception, $code)
{
Log::error($exception);
Log::error($exception);
});

App::missing(function($exception)
{
\Log::info("Missing");
return Response::view('404', array(), 404);
\Log::info("Missing");
return Response::view('404', array(), 404);
});

/*
Expand Down
3 changes: 2 additions & 1 deletion public/app/modules/common/ActivityService.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ function ActivityService (

USER_ACTIONS: {
UPLOAD_PICTURE: 'UPLOAD_PICTURE',
INPUTCODE_SUCCESS: 'INPUTCODE_SUCCESS'
INPUTCODE_SUCCESS: 'INPUTCODE_SUCCESS',
INPUTCODE_ERROR: 'INPUTCODE_ERROR'
},

/// vars
Expand Down
45 changes: 37 additions & 8 deletions public/app/modules/mobidul/station/elements/InputCodeDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ angular
.directive('mblInputCode', InputCode);

InputCode.$inject = [
'$log', '$rootScope'
'$log', '$rootScope',
'ActivityService'
];

function InputCode (
$log, $rootScope
$log, $rootScope,
ActivityService
) {
return {
restrict: 'E',
Expand All @@ -24,7 +26,7 @@ function InputCode (
'<form ng-submit="ctrl.submit()">' +
'<md-input-container>' +
'<input ' +
'ng-model="ctrl.input" ' +
'ng-model="ctrl.code" ' +
'data-success="success" ' +
'data-error="error">' +
'</input>' +
Expand All @@ -33,8 +35,8 @@ function InputCode (
'<md-button ' +
'type="submit" ' +
'class="md-raised md-primary"' +
'>Go</md-button>'
'</form>'
'>Go</md-button>' +
'</form>' +
'</div>'
),

Expand All @@ -48,12 +50,39 @@ function InputCode (
ctrl.submit = submit;

function submit () {
if (ctrl.input) {
if ( ctrl.input.toLowerCase() == $scope.verifier.toLowerCase() ) {
if (ctrl.code) {
var code = ctrl.code.toLowerCase();
var verifier = $scope.verifier.toLowerCase();

var payload = {
inputCodeId: 'unknown',
code: code,
verifier: verifier
};

// Check if the given code matches the verifier
if ( code === verifier ) {
ActivityService.commitActivity({
type: ActivityService.TYPES.USER_ACTION,
name: ActivityService.USER_ACTIONS.INPUTCODE_SUCCESS,
payload: payload
});

$rootScope.$broadcast('action', $scope.success);
} else {
}
else {
ActivityService.commitActivity({
type: ActivityService.TYPES.USER_ACTION,
name: ActivityService.USER_ACTIONS.INPUTCODE_ERROR,
payload: payload
});

$rootScope.$broadcast('action', $scope.error);
}

// TODO: find a better place for pushing the activity
// maybe $on('action', ...) ?
ActivityService.pushActivity();
}
}
},
Expand Down

0 comments on commit 70e6984

Please sign in to comment.