Skip to content

Commit

Permalink
Add feedback on survey save, add 'manage' share option
Browse files Browse the repository at this point in the history
Close #37
Close #31
  • Loading branch information
simonv3 committed Aug 18, 2016
1 parent 3190d93 commit 8a37a9c
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 36 deletions.
13 changes: 12 additions & 1 deletion .sandstorm/sandstorm-pkgdef.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,18 @@ const pkgdef :Spk.PackageDefinition = (
# the app opens while running in dev mode. To see what that looks like,
# run `spk init` without the -A option.)

bridgeConfig = (viewInfo = (permissions = [(name = "owner")]))
bridgeConfig = (
viewInfo = (
permissions = [(name = "owner"), (name = "manage")],
roles = [(title = (defaultText = "manager"),
permissions = [false, true],
verbPhrase = (defaultText = "Can edit survey")),
(title = (defaultText = "respondent"),
permissions = [false, false],
verbPhrase = (defaultText = "Can fill in survey"),
default = true)]
)
)
);

const myCommand :Spk.Manifest.Command = (
Expand Down
1 change: 1 addition & 0 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<div class="page-wrap">
<div class="nav" ng-controller="NavBarCtrl">
<div class="admin" ng-if="is_admin">
Hey {{ Meteor.sandstormUser().name }}!
<a href="/">survey</a>
<a href="/manage">manage</a>
<a ng-if="!on_sandstorm" href="/admin">admin</a>
Expand Down
1 change: 0 additions & 1 deletion client/js/manage/controllers/manageCtrl.ng.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ angular.module('quick-survey').controller('ManageCtrl',
activeSurvey: function() {
if ($scope.activeSurveyId) {
var survey = Surveys.findOne($scope.activeSurveyId);
console.log(survey);
return survey;
}
}
Expand Down
5 changes: 2 additions & 3 deletions client/js/manage/directives/add-question.ng.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ angular.module('quick-survey').directive('addQuestion', function () {
'type': $scope.questionTypes[0].type
};
$scope.showAddQuestionForm = false;
})

})
});
});
};
},
templateUrl: 'client/js/manage/directives/add-question.ng.html',
Expand Down
3 changes: 1 addition & 2 deletions client/js/manage/directives/edit-survey-details.ng.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
</div>
<div class="form-align-group">
<div class="offset">

<button class="submit" ng-click="save(survey)">Save</button>
<span class="inform" ng-if="!form.$pristine">Save your changes!</span>
<i ng-if="saved" class="icon-check"></i>
</div>

</div>
11 changes: 10 additions & 1 deletion client/js/manage/directives/edit-survey-details.ng.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ angular.module('quick-survey').directive('editSurveyDetails', function () {
form: '='
},
controller: function ($scope) {

$scope.saved = false;

$scope.save = function(survey) {
$scope.form.$pristine = true;
$scope.saved = false;

Surveys.update({_id: survey._id},
{ $set: {
name: survey.name,
Expand All @@ -16,7 +21,11 @@ angular.module('quick-survey').directive('editSurveyDetails', function () {
endNote: survey.endNote,
require_sign_in: survey.require_sign_in,
canBeShared: survey.canBeShared
} });
} }, function () {
$scope.$apply(function ( ){
$scope.saved = true;
});
});
};
},
templateUrl: 'client/js/manage/directives/edit-survey-details.ng.html',
Expand Down
39 changes: 19 additions & 20 deletions client/js/routes.ng.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,24 @@
templateUrl: 'client/js/manage/views/manage.ng.html',
controller: 'ManageCtrl',
resolve: {
'currentUser': ['$q', function($q){
var deferred = $q.defer();

Meteor.autorun(function() {
if (!Meteor.loggingIn()){
var user = Meteor.user();
if (user && user.is_admin)
deferred.resolve();
if (user) {
var sandstorm = Meteor.user().services.sandstorm;
if (sandstorm && sandstorm.permissions[0] === 'owner')
deferred.resolve();

}
deferred.reject('UNAUTHORIZED');
}
});

return deferred.promise;
'currentUser': ['$q', '$auth', function($q, $auth){
return checkIfManager($q, $auth);
// Meteor.autorun(function() {
// if (!Meteor.loggingIn()){
// var user = Meteor.user();
// if (user && user.is_admin)
// deferred.resolve();
// if (user) {
// var sandstorm = Meteor.user().services.sandstorm;
// if (sandstorm && sandstorm.permissions[0] === 'owner')
// deferred.resolve();

// }
// deferred.reject('UNAUTHORIZED');
// }
// });

// return deferred.promise;
}],
'activeSurvey': ['$q', function($q) {
var deferred = $q.defer();
Expand Down Expand Up @@ -185,7 +184,7 @@
var user = Meteor.sandstormUser();
if (user) {
var isAdmin = false;
var managePermissions = ['owner', 'manager'];
var managePermissions = ['owner', 'manage'];
managePermissions.forEach(function (permission) {
if (user.permissions.indexOf(permission) > -1) {
isAdmin = true;
Expand Down
25 changes: 17 additions & 8 deletions model/survey.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
Surveys = new Mongo.Collection("surveys");

// TODO, use Meteor Methods to do this kind of stuff.
// Also this can all be simplified if we remove
// the things that rely on Meteor.user();
Surveys.allow({

insert: function (userId, survey) {
if (Meteor.user().is_admin)
if (Meteor.user() && Meteor.user().is_admin)
return true;

var sandstorm = Meteor.user().services.sandstorm;
Expand All @@ -13,19 +16,25 @@ Surveys.allow({
},

update: function (userId, survey, fields, modifier) {
if (Meteor.user().is_admin) {
if (Meteor.user() && Meteor.user().is_admin) {
return true;
}

var sandstorm = Meteor.user().services.sandstorm;
if (sandstorm && sandstorm.permissions[0] === 'owner')
return true;

return false;
var user = DDP._CurrentInvocation.get().connection.sandstormUser();

var managePermissions = ['owner', 'manage'];
var canUpdate = false;
managePermissions.forEach(function (permission) {
// See https://github.com/sandstorm-io/meteor-accounts-sandstorm/issues/19
if (user.permissions.indexOf(permission) > -1) {
canUpdate = true;
}
});
return canUpdate;
},

remove: function (userId, survey) {
if (Meteor.user().is_admin) {
if (Meteor.user() && Meteor.user().is_admin) {
return true;
}

Expand Down

0 comments on commit 8a37a9c

Please sign in to comment.