Skip to content

Commit

Permalink
Post type editor
Browse files Browse the repository at this point in the history
Summary:
What works:
- View a list of all post types
- add/edit/delete post types
- Add/edit/delete form attributes
- Add/edit/delete form stages
- Attribute re-ordering
- Stage re-ordering

Still missing
- Visible To/Editable By permissions - missing on the backend
- Field instructions - also missing on the backend

Test Plan:
Edit a form, add stages and fields save and check they're reflected elsewhere.
Same with a new form.

Reviewers: aMoniker, vladimir, lkamau

Subscribers: rjmackay, vladimir, lkamau, aMoniker

Maniphest Tasks: T1139

Differential Revision: https://phabricator.ushahidi.com/D777
  • Loading branch information
rjmackay committed Jun 18, 2015
1 parent ce179f6 commit 7acfbf2
Show file tree
Hide file tree
Showing 26 changed files with 988 additions and 19 deletions.
1 change: 1 addition & 0 deletions app/common/common-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ angular.module('ushahidi.common', [
.service('UserEndpoint', require('./services/endpoints/user-endpoint.js'))
.service('FormEndpoint', require('./services/endpoints/form.js'))
.service('FormAttributeEndpoint', require('./services/endpoints/form-attributes.js'))
.service('FormStageEndpoint', require('./services/endpoints/form-stages.js'))
.service('TagEndpoint', require('./services/endpoints/tag.js'))
.service('RoleHelper', require('./services/role-helper.js'))
.service('Config', require('./services/config.js'))
Expand Down
52 changes: 47 additions & 5 deletions app/common/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,46 @@
"forbidden": "Sorry, you're not allowed to do that."
},
"form": {
"add_field" : "Add Field",
"edit_field" : "Edit Field",
"add_field" : "Add New Field",
"add_field_instructions": "Add instructions to this field",
"add_field_instructions_info": "These instructions will be presented as a tooltip to a user when filling in this field.",
"add_field_instructions_placeholder": "Instructions for field",
"add_new_step": "Add New Step",
"currently_disabled": "This post type is currently disabled.",
"custom_structure": "Custom Structure",
"default_date_placeholder": "Default date",
"default_default_placeholder": "Default value",
"default_location_placeholder": "Nairobi, Kenya",
"delete_post_type": "Delete this post type",
"editable_by": "Editable By",
"edit_post_step": "Edit Step: {{step}}",
"edit_post_type": "Edit Post Type: {{form}}",
"field_add_option": "Add",
"field_default": "Field Default",
"field_key": "Field Key",
"field_input": "Field Input",
"field_type": "Field Storage",
"field_name": "Field Name",
"field_options": "Field Options",
"field_key_placeholder": "field-key",
"field_name_placeholder": "Title",
"field_option_placeholder": "Option 1",
"field_required": "This field is required",
"form_name": "Post Type Name",
"form_description": "Post Type Description",
"forms" : "Forms",
"type" : "type"
"permission_public": "Public",
"permission_admin": "Admin",
"permission_self": "Only Me",
"post_type_settings": "Post Type Settings",
"post_step_settings": "Post Step Settings",
"save_and_close": "Save & Close",
"save_post_type": "Save Post Type",
"save_post_step": "Save Post Step",
"step_name": "Step Name",
"step_required": "This step is required",
"type" : "type",
"visible_to": "Visible To"
},
"globalFilter": {
"filter" : "Filter",
Expand Down Expand Up @@ -99,7 +135,7 @@
"please_wait_loading" : "Please wait. Loading...",
"plugins" : "Plugins",
"posts" : "Posts",
"posts_and_entities" : "Posts & Entites",
"posts_and_entities" : "Post Types",
"profile": "My Profile",
"role" : "Role",
"roles" : "Roles",
Expand Down Expand Up @@ -372,13 +408,19 @@
"destroy_error" : "Unable to delete user, please try again",
"bulk_destroy_confirm" : "Are you sure you want to delete {{count}} users?",
"bulk_role_change_confirm": "Are you sure you want to change the role of {{count}} users to {{role}}?"
},
"form" : {
"delete_form_confirm" : "Are you sure you want to delete this form?",
"delete_stage_confirm" : "Are you sure you want to delete this step?",
"delete_attribute_confirm" : "Are you sure you want to delete this field?"
}
},
"empty": {
"default" : "No records found.",
"post" : "No posts found.",
"user" : "No users found.",
"category" : "No categories found."
"category" : "No categories found.",
"form": "No forms found."
},
"location": {
"search": "Search",
Expand Down
6 changes: 6 additions & 0 deletions app/common/services/endpoints/form-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ function (
transformResponse: function (data /*, header*/) {
return Util.transformResponse(data).results;
}
},
update: {
method: 'PUT'
},
delete: {
method: 'DELETE'
}
});

Expand Down
31 changes: 31 additions & 0 deletions app/common/services/endpoints/form-stages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = [
'$resource',
'Util',
function (
$resource,
Util
) {

var FormStageEndpoint = $resource(Util.apiUrl('/forms/:formId/stages/:id'), {
formId: '@formId',
id: '@id',
order: 'asc',
orderby: 'priority'
}, {
query: {
method: 'GET',
isArray: true,
transformResponse: function (data /*, header*/) {
return Util.transformResponse(data).results;
}
},
update: {
method: 'PUT'
},
delete: {
method: 'DELETE'
}
});

return FormStageEndpoint;
}];
7 changes: 5 additions & 2 deletions app/common/services/endpoints/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ function (
Util
) {

var FormEndpoint = $resource(Util.apiUrl('/forms/:formId'), {
formId: '@formId'
var FormEndpoint = $resource(Util.apiUrl('/forms/:id'), {
id: '@id'
}, {
query: {
method: 'GET',
isArray: true,
transformResponse: function (data /*, header*/) {
return Util.transformResponse(data).results;
}
},
update: {
method: 'PUT'
}
});

Expand Down
9 changes: 8 additions & 1 deletion app/common/services/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ module.exports = ['$window', function ($window) {
alertMessages.forEach(showSingleAlert);
};

var showConfirm = function (confirmMessage) {
// TODO: find a better solution for that
var confirm = $window.confirm(confirmMessage);
return confirm;
};

return {
showSingleAlert: showSingleAlert,
showAlerts: showAlerts
showAlerts: showAlerts,
showConfirm: showConfirm
};

}];
2 changes: 1 addition & 1 deletion app/post/controllers/post-detail-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function (
if ($scope.post.form && $scope.post.form.id) {
$scope.form_attributes = [];

FormEndpoint.get({formId: $scope.post.form.id}, function (form) {
FormEndpoint.get({id: $scope.post.form.id}, function (form) {
$scope.form_name = form.name;

// Set page title to '{form.name} Details' if a post title isn't provided.
Expand Down
2 changes: 1 addition & 1 deletion app/post/controllers/post-edit-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function (
post.tags = tags;

$scope.post = post;
$scope.active_form = FormEndpoint.get({ formId: post.form.id }, function (form) {
$scope.active_form = FormEndpoint.get({ id: post.form.id }, function (form) {
// Set page title to post title, if there is one available.
if (post.title && post.title.length) {
$translate('post.modify.edit_type', { type: form.name, title: post.title }).then(function (title) {
Expand Down
2 changes: 1 addition & 1 deletion app/post/directives/post-preview-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function (
});

if (scope.post.form) {
FormEndpoint.get({formId: scope.post.form.id}, function (form) {
FormEndpoint.get({id: scope.post.form.id}, function (form) {
scope.form_name = form.name;
});
} else {
Expand Down
37 changes: 32 additions & 5 deletions app/setting/controllers/setting-forms-controller.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
module.exports = [
'$scope',
'$translate',
'$location',
'FormEndpoint',
function (
$scope,
$translate
$translate,
$location,
FormEndpoint
) {

$translate('tool.manage_forms').then(function (title) {
$scope.title = title;
$scope.$emit('setPageTitle', title);
});
$translate('nav.posts_and_entities').then(function (title) {
$scope.title = title;
$scope.$emit('setPageTitle', title);
});

// Get all the forms for display
FormEndpoint.get().$promise.then(function (response) {
$scope.forms = response.results;
});

// Manage new form settings
$scope.isNewFormOpen = false;
$scope.openNewForm = function () {
$scope.newForm = {};
$scope.isNewFormOpen = !$scope.isNewFormOpen;
};
$scope.saveNewForm = function (form) {
FormEndpoint
.save(form)
.$promise
.then(function (form) {
$scope.isNewFormOpen = false;
$scope.newForm = {};
$location.url('/settings/forms/' + form.id);
});
};
// End new form

}];
35 changes: 35 additions & 0 deletions app/setting/controllers/setting-forms-create-controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module.exports = [
'$scope',
'$q',
'FormEndpoint',
'FormAttributeEndpoint',
'_',
function (
$scope,
$q,
FormEndpoint,
FormAttributeEndpoint,
_
) {

// Get all the forms for display
FormEndpoint.get().$promise.then(function (response) {
var forms = response.results;

// Get all form attributes for each form
var attribute_promises = [];
_.each(forms, function (form) {
attribute_promises.push(
FormAttributeEndpoint.query({ formId: form.id }).$promise
);
});

$q.all(attribute_promises).then(function (data) {
_.each(data, function (datum, idx) {
forms[idx].attributes = [].concat(data[idx]);
});
$scope.forms = forms;
});
});

}];
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = [
'$scope',
'$routeParams',
function (
$scope,
$routeParams
) {

$scope.form_template = $routeParams.id;

}];
28 changes: 28 additions & 0 deletions app/setting/controllers/setting-forms-edit-controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports = [
'$scope',
'$routeParams',
'$q',
'FormEndpoint',
'FormStageEndpoint',
function (
$scope,
$routeParams,
$q,
FormEndpoint,
FormStageEndpoint
) {

$scope.formId = $routeParams.id;

// If we're editing an existing form,
// load the form info and all the fields.
$q.all([
FormEndpoint.get({ id: $scope.formId }).$promise,
FormStageEndpoint.query({ formId: $scope.formId }).$promise
]).then(function (results) {
var form = results[0];
form.stages = results[1];
$scope.form = form;
});

}];
28 changes: 28 additions & 0 deletions app/setting/controllers/setting-forms-edit-stage-controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports = [
'$scope',
'$routeParams',
'$q',
'FormEndpoint',
'FormStageEndpoint',
function (
$scope,
$routeParams,
$q,
FormEndpoint,
FormStageEndpoint
) {

$scope.formId = $routeParams.formId;
$scope.stageId = $routeParams.id;

// If we're editing an existing form,
// load the form info and all the fields.
$q.all([
FormEndpoint.get({ id: $scope.formId }).$promise,
FormStageEndpoint.get({ formId: $scope.formId, id: $scope.stageId }).$promise
]).then(function (results) {
$scope.form = results[0];
$scope.stage = results[1];
});

}];
Loading

0 comments on commit 7acfbf2

Please sign in to comment.