Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/product-sprint6-staging' into pr…
Browse files Browse the repository at this point in the history
…oduct-sprint6-173-merger
  • Loading branch information
kaladay committed Sep 14, 2020
2 parents b5beefc + 74aa1b7 commit a42416c
Show file tree
Hide file tree
Showing 14 changed files with 639 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ app.controller('ServiceDetailFeatureProposalListController', function ($controll
}, 500);
});

if (!$scope.isAnonymous()) {
UserRepo.getUser().then(function (res) {
var apiRes = angular.fromJson(res.body);
if (apiRes.meta.status === 'SUCCESS') {
$scope.user = apiRes.payload.User;
$scope.hasVoted = function (fp) {
return fp.voters.map(function(v) { return v.id; }).indexOf($scope.user.id) >= 0;
};
}
});
}
UserRepo.ready().then(function () {
if (!$scope.isAnonymous()) {
UserRepo.getUser().then(function (res) {
var apiRes = angular.fromJson(res.body);
if (apiRes.meta.status === 'SUCCESS') {
$scope.user = apiRes.payload.User;
$scope.hasVoted = function (fp) {
return fp.voters.map(function(v) { return v.id; }).indexOf($scope.user.id) >= 0;
};
}
});
}
});

$scope.isVotingOpen = function (featureProposal) {
return !$scope.isAnonymous() && featureProposal.state === FeatureProposalState.ACTIVE.value;
Expand All @@ -58,4 +60,4 @@ app.controller('ServiceDetailFeatureProposalListController', function ($controll
});
};

});
});
53 changes: 38 additions & 15 deletions app/repo/ideaRepo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
app.repo("IdeaRepo", function IdeaRepo(WsApi, Idea, ServiceRepo, TableFactory) {
app.repo("IdeaRepo", function IdeaRepo(WsApi, Idea, ServiceRepo, TableFactory, UserService) {

var ideaRepo = this;

Expand Down Expand Up @@ -59,23 +59,46 @@ app.repo("IdeaRepo", function IdeaRepo(WsApi, Idea, ServiceRepo, TableFactory) {
}
};

WsApi.listen(ideaRepo.mapping.createListen).then(null, null, function (response) {
ServiceRepo.addIdea(new Idea(angular.fromJson(response.body).payload.Idea));
table.getTableParams().reload();
});
var canAccess = function () {
var user = UserService.getCurrentUser();
var access = false;

WsApi.listen(ideaRepo.mapping.updateListen).then(null, null, function (response) {
var idea = new Idea(angular.fromJson(response.body).payload.Idea);
ServiceRepo.updateIdea(idea);
updateIdea(idea);
table.getTableParams().reload();
});
if (user.role === undefined || user.role === null || user.anonymous) {
access = false;
}
else if (user.role === 'ROLE_ADMIN') {
access = true;
} else if (user.role === 'ROLE_SERVICE_ADMIN') {
access = true;
} else if (user.role === 'ROLE_SERVICE_MANAGER') {
access = true;
}

return access;
};

UserService.userReady().then(function () {
if (canAccess()) {

WsApi.listen(ideaRepo.mapping.createListen).then(null, null, function (response) {
ServiceRepo.addIdea(new Idea(angular.fromJson(response.body).payload.Idea));
table.getTableParams().reload();
});

WsApi.listen(ideaRepo.mapping.deleteListen).then(null, null, function (response) {
ServiceRepo.removeIdeaById(angular.fromJson(response.body).payload.Long);
table.getTableParams().reload();
WsApi.listen(ideaRepo.mapping.updateListen).then(null, null, function (response) {
var idea = new Idea(angular.fromJson(response.body).payload.Idea);
ServiceRepo.updateIdea(idea);
updateIdea(idea);
table.getTableParams().reload();
});

WsApi.listen(ideaRepo.mapping.deleteListen).then(null, null, function (response) {
ServiceRepo.removeIdeaById(angular.fromJson(response.body).payload.Long);
table.getTableParams().reload();
});
}
});

return ideaRepo;

});
});
12 changes: 7 additions & 5 deletions app/repo/userRepo.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
app.repo("UserRepo", function UserRepo(WsApi) {

this.getUser = function () {
return WsApi.fetch(this.mapping.getUser);
};
var userRepo = this;

return this;
userRepo.getUser = function () {
return WsApi.fetch(this.mapping.getUser);
};

});
return userRepo;

});
11 changes: 1 addition & 10 deletions app/services/productService.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,7 @@ app.service('ProductService', function ($q, WsApi) {
angular.extend(apiMapping.Product.submitFeatureProposal, {
'data': fp
});
return $q(function (resolve, reject) {
WsApi.fetch(apiMapping.Product.submitFeatureProposal).then(function (response) {
var apiRes = angular.fromJson(response.body);
if (apiRes.meta.status === 'SUCCESS') {
resolve();
} else {
reject();
}
});
});
return WsApi.fetch(apiMapping.Product.submitFeatureProposal);
};

});
1 change: 0 additions & 1 deletion app/views/directives/featureProposal.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<div class="row">
<div class="lead col-md-8">
<span>{{featureProposal.title}}</span>
<span> ({{featureProposal.state | featureProposalState}})</span>
</div>
<div class="lead col-md-4" ng-if="!isAnonymous()">
<span ng-if="hasVoted(featureProposal)" class="glyphicon glyphicon-ok text-success pull-right"></span>
Expand Down
4 changes: 4 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ module.exports = function (config) {

'app/repo/**/*.js',

'app/views/**/*.html',

'tests/core/**/*.js',

'tests/mocks/**/*.js',

'tests/unit/**/*.js'
Expand Down
112 changes: 112 additions & 0 deletions tests/core/mocks/mockAbstractCoreModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
var mockModel = function (modelName, $q, mockDataObj) {
var model = {};
var shadow = {};
var combinationOperation = "";

model.isDirty = false;
model.isValid = false;

model.mock = function (toMock) {
if (typeof toMock === "object") {
var keys = Object.keys(toMock);
for (var i in keys) {
model[keys[i]] = toMock[keys[i]];
}
} else if (toMock === undefined || toMock === null) {
model = null;
}
};

model.mockShadow = function (toMock) {
shadow = toMock;
};

model.acceptPendingUpdate = function () {
};

model.acceptPendingDelete = function () {
};

model.before = function () {
};

model.clearListens = function () {
var payload = {};
return payloadPromise($q.defer(), payload);
};

model.clearValidationResults = function () {
};

model.delete = function () {
return payloadPromise($q.defer(), true);
};

model.dirty = function (boolean) {
if (boolean !== undefined) {
model.isDirty = boolean;
}

return model.isDirty;
};

model.enableMergeCombinationOperation = function () {
combinationOperation = "merge";
};

model.enableExtendCombinationOperation = function () {
combinationOperation = "extend";
};

model.fetch = function () {
return payloadPromise($q.defer(), mockDataObj);
};

model.getCombinationOperation = function () {
return combinationOperation;
};

model.getEntityName = function () {
return modelName;
};

model.getValidations = function () {
return null;
};

model.init = function (data, apiMapping) {
};

model.listen = function () {
};

model.ready = function () {
var defer = $q.defer();
defer.resolve();
return defer.promise;
};

model.refresh = function () {
angular.extend(model, shadow);
};

model.reload = function () {
var defer = $q.defer();
defer.resolve(model);
return defer.promise;
};

model.save = function () {
return payloadPromise($q.defer(), true);
};

model._syncShadow = function () {
model.isDirty = false;
shadow = angular.copy(model);
};

model.mock(mockDataObj);
model._syncShadow();

return model;
};
Loading

0 comments on commit a42416c

Please sign in to comment.