Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Improve Disabled View Handling #400

Merged
merged 2 commits into from
Apr 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/blog/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
template: '<p class="form-control-static"><a ng-click="displayPost()">View&nbsp;post</a></p>',
link: function (scope) {
scope.displayPost = function () {
$location.path('/show/posts/' + scope.entry().values.post_id);
$location.path('/posts/show/' + scope.entry().values.post_id);
};
}
};
Expand Down
6 changes: 4 additions & 2 deletions src/javascripts/ng-admin/Crud/column/maColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ define(function (require) {
$compile(element.contents())(scope);
scope.gotoDetail = function () {
this.clearRouteParams();
var route = scope.entity().isReadOnly ? 'show' : scope.field.detailLinkRoute();

var route = scope.field.detailLinkRoute();
if (route == 'edit' && !scope.entity().editionView().enabled) {
route = 'show';
}
$location.path('/' + scope.entry.entityName + '/' + route + '/' + scope.entry.identifierValue);
$anchorScroll(0);
};
Expand Down
12 changes: 6 additions & 6 deletions src/javascripts/ng-admin/Crud/delete/batchDelete.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<div class="row list-header">
<div class="col-lg-12">
<ma-view-actions override="batchDeleteController.actions" selection="batchDeleteController.selection" entity="batchDeleteController.entity">
<ma-list-button entity="entity"></ma-list-button>
<ma-view-actions override="::batchDeleteController.actions" selection="batchDeleteController.selection" entity="::batchDeleteController.entity">
<ma-list-button entity="::entity"></ma-list-button>
</ma-view-actions>

<div class="page-header">
<h1 compile="batchDeleteController.title">
Delete {{ batchDeleteController.entityIds.length }} {{ batchDeleteController.view.entity.name() | humanize | pluralize }}
<h1 compile="::batchDeleteController.title">
Delete {{ ::batchDeleteController.entityIds.length }} {{ ::batchDeleteController.view.entity.name() | humanize | pluralize }}
</h1>
</div>
</div>
Expand All @@ -20,9 +20,9 @@ <h1 compile="batchDeleteController.title">
</div>
</div>

<div ng-if="selection" class="row list-view" ng-class="'ng-admin-entity-' + batchDeleteController.entity.name()">
<div ng-if="selection" class="row list-view" ng-class="::'ng-admin-entity-' + batchDeleteController.entity.name()">
<div class="col-lg-12">
<ma-datagrid name="{{ batchDeleteController.view.name() }}"
<ma-datagrid name="{{ ::batchDeleteController.view.name() }}"
entries="batchDeleteController.selection"
fields="::batchDeleteController.fields"
entity="::batchDeleteController.entity">
Expand Down
10 changes: 5 additions & 5 deletions src/javascripts/ng-admin/Crud/delete/delete.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<div class="row">
<div class="col-lg-12">
<ma-view-actions override="deleteController.actions" entry="entry" entity="deleteController.entity">
<ma-list-button entity="entity"></ma-list-button>
<ma-view-actions override="::deleteController.actions" entry="::entry" entity="::deleteController.entity">
<ma-list-button entity="::entity"></ma-list-button>
</ma-view-actions>

<div class="page-header">
<h1 compile="deleteController.title">
Delete {{ deleteController.view.entity.name() | humanize:true | singularize }} #{{ entry.identifierValue }}
<h1 compile="::deleteController.title">
Delete {{ ::deleteController.view.entity.name() | humanize:true | singularize }} #{{ ::entry.identifierValue }}
</h1>
<p class="lead" ng-if="deleteController.description" compile="deleteController.description">{{ deleteController.description }}</p>
<p class="lead" ng-if="::deleteController.description" compile="::deleteController.description">{{ ::deleteController.description }}</p>
</div>
</div>
</div>
Expand Down
24 changes: 8 additions & 16 deletions src/javascripts/ng-admin/Crud/form/FormController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
define(function () {
'use strict';

var FormController = function ($scope, $location, CreateQueries, UpdateQueries, Validator, Configuration,
var FormController = function ($scope, $state, CreateQueries, UpdateQueries, Validator, Configuration,
progression, notification, view, entry) {

this.$scope = $scope;
this.$location = $location;
this.$state = $state;
this.CreateQueries = CreateQueries;
this.UpdateQueries = UpdateQueries;
this.Validator = Validator;
Expand All @@ -20,7 +20,6 @@ define(function () {
this.config = Configuration();
this.view = view;
this.entity = this.view.getEntity();
this.$scope.edit = this.edit.bind(this);
this.$scope.entry = entry;
this.$scope.view = view;
this.$scope.entity = this.entity;
Expand Down Expand Up @@ -71,20 +70,22 @@ define(function () {
FormController.prototype.submitCreation = function ($event) {
$event.preventDefault();
var entry = this.validateEntry();
var entity = this.$scope.entity;
var route = !entity.editionView().enabled ? 'show' : 'edit';
if (!entry) {
return;
}
var progression = this.progression,
notification = this.notification,
entity = this.entity,
$location = this.$location;
$state = this.$state;
progression.start();
this.CreateQueries
.createOne(this.view, entry)
.then(function (response) {
progression.done();
notification.log('Element successfully created.', {addnCls: 'humane-flatty-success'});
$location.path(entity.name() + '/edit/' + response.identifierValue);
$state.go($state.get(route), { entity: entity.name(), id: response.identifierValue });
}, this.handleError.bind(this));
};

Expand All @@ -105,15 +106,6 @@ define(function () {
}, this.handleError.bind(this));
};

/**
* Link to edit entity page
*
* @param {View} entry
*/
FormController.prototype.edit = function (entry) {
this.$location.path(entry.entityName + '/edit/' + entry.identifierValue);
};

/**
* Handle create or update errors
*
Expand All @@ -128,14 +120,14 @@ define(function () {

FormController.prototype.destroy = function () {
this.$scope = undefined;
this.$location = undefined;
this.$state = undefined;
this.CreateQueries = undefined;
this.UpdateQueries = undefined;
this.view = undefined;
this.entity = undefined;
};

FormController.$inject = ['$scope', '$location', 'CreateQueries', 'UpdateQueries', 'Validator', 'NgAdminConfiguration', 'progression', 'notification', 'view', 'entry'];
FormController.$inject = ['$scope', '$state', 'CreateQueries', 'UpdateQueries', 'Validator', 'NgAdminConfiguration', 'progression', 'notification', 'view', 'entry'];

return FormController;
});
14 changes: 7 additions & 7 deletions src/javascripts/ng-admin/Crud/form/create.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<div class="row">
<div class="col-lg-12">
<ma-view-actions override="formController.actions" entry="entry" entity="formController.entity">
<ma-list-button entity="entity"></ma-list-button>
<ma-view-actions override="::formController.actions" entry="entry" entity="::formController.entity">
<ma-list-button entity="::entity"></ma-list-button>
</ma-view-actions>

<div class="page-header">
<h1 compile="formController.title">
Create new {{ formController.view.entity.name() | humanize:true | singularize }}
<h1 compile="::formController.title">
Create new {{ ::formController.view.entity.name() | humanize:true | singularize }}
</h1>
<p class="lead" ng-if="formController.description" compile="formController.description">{{ formController.description }}</p>
<p class="lead" ng-if="::formController.description" compile="::formController.description">{{ ::formController.description }}</p>
</div>
</div>
</div>

<div class="row" id="create-view" ng-class="'ng-admin-entity-' + formController.entity.name()">
<div class="row" id="create-view" ng-class="::'ng-admin-entity-' + formController.entity.name()">
<form class="col-lg-12 form-horizontal" name="formController.form" ng-submit="formController.submitCreation($event)">
<div class="form-field form-group" ng-repeat="field in formController.fields track by $index">
<div class="form-field form-group" ng-repeat="field in ::formController.fields track by $index">
<ma-field field="::field" entry="entry" entity="::entity" form="formController.form"></ma-field>
</div>

Expand Down
16 changes: 8 additions & 8 deletions src/javascripts/ng-admin/Crud/form/edit.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<div class="row">
<div class="col-lg-12">
<ma-view-actions override="formController.actions" entry="entry" entity="formController.entity">
<ma-list-button entity="entity"></ma-list-button>
<ma-delete-button entry="entry" entity="entity"></ma-delete-button>
<ma-view-actions override="::formController.actions" entry="entry" entity="::formController.entity">
<ma-list-button entity="::entity"></ma-list-button>
<ma-delete-button ng-if="::entity.deletionView().enabled" entry="entry" entity="::entity"></ma-delete-button>
</ma-view-actions>

<div class="page-header">
<h1 compile="formController.title">
Edit {{ formController.entity.name() | humanize:true | singularize }} #{{ entry.identifierValue }}
<h1 compile="::formController.title">
Edit {{ ::formController.entity.name() | humanize:true | singularize }} #{{ ::entry.identifierValue }}
</h1>
<p class="lead" ng-if="formController.description" compile="formController.description">{{ formController.description }}</p>
<p class="lead" ng-if="::formController.description" compile="::formController.description">{{ ::formController.description }}</p>
</div>
</div>
</div>

<div class="row" id="edit-view" ng-class="'ng-admin-entity-' + formController.entity.name()">
<div class="row" id="edit-view" ng-class="::'ng-admin-entity-' + formController.entity.name()">
<form class="col-lg-12 form-horizontal" name="formController.form" ng-submit="formController.submitEdition($event)">
<div class="form-field form-group" ng-repeat="field in formController.fields track by $index">
<div class="form-field form-group" ng-repeat="field in ::formController.fields track by $index">
<ma-field field="::field" entry="entry" entity="::entity" form="formController.form"></ma-field>
</div>

Expand Down
4 changes: 2 additions & 2 deletions src/javascripts/ng-admin/Crud/list/DatagridController.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ define(function () {
*/
DatagridController.prototype.gotoDetail = function (entry) {
this.clearRouteParams();
var route = this.$scope.entity.isReadOnly ? 'show' : 'edit';

var entity = this.$scope.entity;
var route = entity.editionView().enabled ? 'edit' : 'show';
this.$location.path('/' + entry.entityName + '/' + route + '/' + entry.identifierValue);
this.$anchorScroll(0);
};
Expand Down
8 changes: 4 additions & 4 deletions src/javascripts/ng-admin/Crud/list/ListActions.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<span compile="customTemplate">
<span ng-repeat="button in buttons" ng-switch="button">
<ma-show-button ng-switch-when="show" entry="entry" entity="entity" size="xs"></ma-show-button>
<ma-edit-button ng-switch-when="edit" entry="entry" entity="entity" size="xs"></ma-edit-button>
<ma-delete-button ng-switch-when="delete" entry="entry" entity="entity" size="xs"></ma-delete-button>
<span ng-repeat="button in ::buttons" ng-switch="button">
<ma-show-button ng-switch-when="show" entry="::entry" entity="::entity" size="xs"></ma-show-button>
<ma-edit-button ng-switch-when="edit" ng-if="::entity.editionView().enabled" entry="::entry" entity="::entity" size="xs"></ma-edit-button>
<ma-delete-button ng-switch-when="delete" ng-if="::entity.deletionView().enabled" entry="::entry" entity="::entity" size="xs"></ma-delete-button>
<span ng-switch-default><span compile="button"></span></span>
</span>
</span>
32 changes: 16 additions & 16 deletions src/javascripts/ng-admin/Crud/list/list.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<div class="row list-header">
<div class="col-lg-12">
<ma-view-actions override="listController.actions" selection="listController.selection" batch-buttons="listController.batchActions" entity="listController.entity">
<ma-view-batch-actions buttons="batchButtons()" selection="selection" entity="entity"></ma-view-batch-actions>
<ma-create-button ng-if="!entity.isReadOnly" entity="entity"></ma-create-button>
<ma-export-to-csv-button entity="entity"></ma-export-to-csv-button>
<ma-view-actions override="::listController.actions" selection="listController.selection" batch-buttons="::listController.batchActions" entity="::listController.entity">
<ma-view-batch-actions buttons="::batchButtons()" selection="selection" entity="::entity"></ma-view-batch-actions>
<ma-create-button ng-if="::entity.creationView().enabled" entity="::entity"></ma-create-button>
<ma-export-to-csv-button entity="::entity"></ma-export-to-csv-button>
</ma-view-actions>

<div class="page-header">
<h1 compile="listController.title">
{{ listController.view.entity.name() | humanize | pluralize }} list
<h1 compile="::listController.title">
{{ ::listController.view.entity.name() | humanize | pluralize }} list
</h1>
<p class="lead" ng-if="listController.description" compile="listController.description">{{ listController.description }}</p>
<p class="lead" ng-if="::listController.description" compile="::listController.description">{{ ::listController.description }}</p>
</div>

<ma-filter ng-if="listController.hasFilters" filters="::listController.filters"></ma-filter>
</div>
</div>

<div class="row list-view" ng-class="'ng-admin-entity-' + listController.entity.name()">
<div class="row list-view" ng-class="::'ng-admin-entity-' + listController.entity.name()">
<div class="col-lg-12">
<ma-datagrid name="{{ listController.view.name() }}"
<ma-datagrid name="{{ ::listController.view.name() }}"
entries="listController.entries"
selection="listController.selection"
fields="::listController.fields"
Expand All @@ -29,19 +29,19 @@ <h1 compile="listController.title">
</div>
</div>

<div class="row" ng-if="!listController.infinitePagination">
<div class="row" ng-if="::!listController.infinitePagination">
<div class="col-lg-12">
<ma-datagrid-pagination
page="{{ listController.page }}"
per-page="{{ listController.view.perPage() }}"
per-page="{{ ::listController.view.perPage() }}"
total-items="{{ listController.totalItems }}"
set-page="listController.setPageCallback">
set-page="::listController.setPageCallback">
</ma-datagrid-pagination>
</div>
</div>

<ma-datagrid-infinite-pagination ng-if="listController.infinitePagination"
per-page="{{ listController.view.perPage() }}"
total-items="{{ listController.totalItems }}"
next-page="listController.nextPageCallback">
<ma-datagrid-infinite-pagination ng-if="::listController.infinitePagination"
per-page="{{ ::listController.view.perPage() }}"
total-items="{{ ::listController.totalItems }}"
next-page="::listController.nextPageCallback">
</ma-datagrid-infinite-pagination>
18 changes: 9 additions & 9 deletions src/javascripts/ng-admin/Crud/show/show.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<div class="row">
<div class="col-lg-12">
<ma-view-actions override="showController.actions" entry="entry" entity="showController.entity">
<ma-list-button entity="entity"></ma-list-button>
<ma-edit-button ng-if="!entity.isReadOnly" entry="entry" entity="entity"></ma-edit-button>
<ma-delete-button ng-if="!entity.isReadOnly" entry="entry" entity="entity"></ma-delete-button>
<ma-view-actions override="::showController.actions" entry="entry" entity="::showController.entity">
<ma-list-button entity="::entity"></ma-list-button>
<ma-edit-button ng-if="::entity.editionView().enabled" entry="entry" entity="::entity"></ma-edit-button>
<ma-delete-button ng-if="::entity.deletionView().enabled" entry="entry" entity="::entity"></ma-delete-button>
</ma-view-actions>

<div class="page-header">
<h1 compile="showController.title">
{{ showController.view.entity.name() | humanize:true | singularize }} #{{ entry.identifierValue }} Detail
<h1 compile="::showController.title">
{{ ::showController.view.entity.name() | humanize:true | singularize }} #{{ ::entry.identifierValue }} Detail
</h1>
<p class="lead" ng-if="showController.description" compile="showController.description">{{ showController.description }}</p>
<p class="lead" ng-if="::showController.description" compile="::showController.description">{{ ::showController.description }}</p>
</div>
</div>
</div>


<div class="row form-horizontal" id="show-view">

<div class="col-lg-12 form-group" ng-repeat="field in showController.fields track by $index">
<div class="col-lg-12 form-group" ng-repeat="field in ::showController.fields track by $index">

<label class="col-sm-2 control-label">{{ field.label() }}</label>

<div class="show-value" ng-class="'ng-admin-field-' + field.name() + ' ' + (field.getCssClasses(entry) || 'col-sm-10 col-md-8 col-lg-7')">
<div class="show-value" ng-class="::'ng-admin-field-' + field.name() + ' ' + (field.getCssClasses(entry) || 'col-sm-10 col-md-8 col-lg-7')">

<ma-column field="::field" entry="::entry" entity="::entity"></ma-column>

Expand Down
5 changes: 3 additions & 2 deletions src/javascripts/ng-admin/Main/run/ErrorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
define(function () {
'use strict';

function errorHandler($rootScope, $state, $location) {
function errorHandler($rootScope, $state, notification) {
$rootScope.$on("$stateChangeError", function handleError(event, toState, toParams, fromState, fromParams, error) {
if (error.status == 404) {
$state.go('ma-404');
event.preventDefault();
} else {
notification.log('State change error: ' + error.message, { addnCls: 'humane-flatty-error' });
throw error;
}
});
}

errorHandler.$inject = ['$rootScope', '$state', '$location'];
errorHandler.$inject = ['$rootScope', '$state', 'notification'];

return errorHandler;
});
8 changes: 7 additions & 1 deletion src/javascripts/ng-admin/Main/run/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ define(function () {
function loader($rootScope, $window, progression) {
$rootScope.$on('$stateChangeStart', function () {
progression.start();
});

$rootScope.$on('$stateChangeSuccess', function() {
progression.done();
$window.scrollTo(0, 0);
});

$rootScope.$on('$stateChangeSuccess', progression.done.bind(progression));
$rootScope.$on("$stateChangeError", function() {
progression.done();
});
}

loader.$inject = ['$rootScope', '$window', 'progression'];
Expand Down