diff --git a/Makefile b/Makefile index 3b358015..0fb77887 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .PHONY: build watch: - ./node_modules/webpack-dev-server/bin/webpack-dev-server.js --progress --colors --host=0.0.0.0 + @./node_modules/webpack-dev-server/bin/webpack-dev-server.js --progress --colors --host=0.0.0.0 install: bower install @@ -12,11 +12,11 @@ run: @grunt build-dev: - @grunt build:dev + @./node_modules/webpack/bin/webpack.js --progress @echo "Files build/ng-admin.min.css and build/ng-admin.min.js updated (no minification)" build: - @grunt build + @NODE_ENV=production ./node_modules/webpack/bin/webpack.js -p --progress @echo "Files build/ng-admin.min.css and build/ng-admin.min.js updated (with minification)" test: diff --git a/examples/blog/stub-server.json b/examples/blog/stub-server.json index eed775d2..3821a970 100644 --- a/examples/blog/stub-server.json +++ b/examples/blog/stub-server.json @@ -142,8 +142,8 @@ }, { "id": 11, - "title": "Omnis voluptate enim similique est possimus", - "teaser": "Velit eos vero reprehenderit ut assumenda saepe qui. Quasi aut laboriosam quas voluptate voluptatem. Et eos officia repudiandae quaerat. Mollitia libero numquam laborum eos.", + "title": "Omnis voluptate enim similique est possimus!!", + "teaser": "Velit eos vero reprehenderit ut assumenda saepe qui. Quasi aut laboriosam quas voluptate voluptatem. Et eos officia repudiandae quaerat. Mollitia libero numquam laborum eos.!!", "body": "
Ut qui a quis culpa impedit. Harum quae sunt aspernatur dolorem minima et dolorum. Consequatur sunt eveniet sit perspiciatis fuga praesentium. Quam voluptatem a ullam accusantium debitis eum consectetur.
Voluptas rem impedit omnis maiores saepe. Eum consequatur ut et consequatur repellat. Quos dolorem dolorum nihil dolor sit optio velit. Quasi quaerat enim omnis ipsum.
Officia asperiores ut doloribus. Architecto iste quia illo non. Deleniti enim odio aut amet eveniet. Modi sint aut excepturi quisquam error sed officia. Nostrum enim repellendus inventore minus. Itaque vitae ipsam quasi. Qui provident vero ab facere. Sit enim provident doloremque minus quam. Voluptatem expedita est maiores nihil est voluptatem error. Asperiores ut a est ducimus hic optio. Natus omnis ullam consectetur ducimus nisi sint ducimus odit. Soluta cupiditate ipsam magnam.
Illum magni aut autem in sed iure. Ea explicabo ducimus officia corrupti ipsam minima minima. Nihil ab similique modi sunt unde nisi. Iusto quis iste ut aut earum magni. Nisi nisi minima sapiente quos aut libero maxime. Ut consequuntur sit vel odio suscipit fugiat tempore et. Et eveniet aut voluptatibus aliquid accusantium quis qui et. Veniam rem ut et. Vel officiis et voluptatum eaque ipsum sit. Sed iste rem ipsam dolor maiores. Et animi aspernatur aut error. Quisquam veritatis voluptatem magnam id. Blanditiis dolorem quo et voluptatum.
Ratione facilis architecto corrupti perspiciatis. Rerum quos illo exercitationem. Dicta autem nulla non libero tempora deserunt. Doloremque nesciunt doloremque voluptate molestias sit neque itaque.
Quia officia a at laudantium et eligendi. Aut adipisci voluptates iure voluptatum accusamus quia. Quo at aliquid adipisci.
Voluptatem ab aut laboriosam possimus rerum necessitatibus. Iusto nihil hic incidunt sequi eius. Voluptatem est corrupti ut nostrum. Necessitatibus excepturi aut fuga aspernatur necessitatibus. Quod magni aliquam assumenda molestiae vitae. Corrupti est quia esse nulla earum sit. Quas eligendi itaque quis ut temporibus qui. Veritatis ducimus ratione incidunt numquam veritatis sed dicta. Explicabo vero maiores dolore est. Fuga facilis minus sapiente sit dolorem. Cum ea magni omnis aliquid eum et id. Doloribus consequuntur excepturi et. Eligendi voluptas velit eum voluptatem sit. Atque et magni distinctio fugiat. Qui quis animi laborum veniam est accusantium. Aliquid fugiat cupiditate labore. Perspiciatis itaque velit deserunt. Ipsum quibusdam officia dolore labore.
Quas in esse fugit iste culpa perspiciatis et. Odit sunt natus aut ut reiciendis. Expedita commodi debitis placeat tempore. Occaecati iure fugit ullam.
Est est quas architecto aut dolores explicabo veniam. Molestias esse vel voluptatem saepe eos ut. Asperiores et molestias et veritatis dolore.
Voluptas et ad distinctio et suscipit voluptatem autem. Deserunt quod doloribus non dolorum ut sed maxime excepturi. Et repudiandae doloribus ab nisi.
Quo quia accusamus dolor reprehenderit. Iste est veritatis praesentium odit.
Ut aut ratione accusamus distinctio delectus. Voluptas neque quidem nemo minima dolore sequi rerum nihil. Ipsum vel nostrum consectetur quas aut. Amet non vel in eos corrupti hic. Qui minima recusandae quos odit. Minima animi earum quia tempore odio officiis. Similique occaecati facilis culpa autem. Illum aut a laborum accusamus. Neque quibusdam dolorem et cum voluptas cum adipisci ea. Nihil necessitatibus ea porro molestias reprehenderit. Molestias delectus nam totam vitae sapiente. Quae asperiores aspernatur odit repellat eveniet. Qui ut et laboriosam.
Veritatis commodi maiores quam vitae omnis. Et et in voluptates eum corporis. Corrupti delectus rerum voluptatem nihil eum et eos. Assumenda animi optio enim omnis ut voluptatem. Quaerat aut voluptatem quam reprehenderit ut quo ad porro. Dicta occaecati ullam temporibus eos non sit. Vero et nihil earum incidunt eaque atque sunt.
Cupiditate voluptas rerum nesciunt repellendus fuga facilis libero. Eveniet est sed iste labore. Laboriosam aut sit officiis et voluptates omnis. Iste voluptatibus sed deserunt voluptatem. Non eius libero voluptas minima rerum. Enim omnis alias at qui. Distinctio ea et vero sunt. A et eius quaerat quasi et illum dolor. Ducimus debitis est magnam ab non. Voluptatibus aut aperiam assumenda mollitia quia explicabo.
Sequi animi et eos voluptate sed. Et dolores iure iusto. Velit id nesciunt labore provident.
Dolorem ullam molestias nihil iste quis fuga omnis. Rerum eum suscipit sunt saepe et odio. Quia omnis recusandae qui repellendus esse quia. Et omnis sunt magni voluptatibus. Odio perspiciatis et numquam qui. Libero nisi et autem culpa accusamus. Laborum eius incidunt maiores voluptate voluptas. Cum in porro ipsa. Similique sit qui quo tempora id tempore. Aliquid cumque nisi quam porro occaecati labore harum. Maxime nisi vel libero sequi.
Amet veniam repudiandae nihil est nisi sunt hic. Blanditiis alias eos aperiam. Aut consectetur adipisci enim odio dolor. Dolores et et nihil et aut tempora. Libero incidunt qui modi. At quia rerum et numquam provident cumque. Odio nobis occaecati impedit ad alias. Laudantium iusto sapiente voluptas blanditiis. Numquam voluptate repudiandae non vel nulla id voluptas unde. Doloremque et natus illo veritatis. Debitis rem molestiae inventore voluptatem iste quos earum. Veritatis sit ut voluptatem non est. Sequi eos eveniet similique sunt tenetur.
Occaecati fuga ipsam aut minima cumque vitae. Eos aut omnis quas.
Et laudantium commodi maxime debitis consequatur cum omnis. Odit suscipit voluptatem dolorem optio aut natus officia aut. Voluptatem rem est et amet sed.
Tempore reiciendis omnis odit labore. Ea esse eligendi voluptatum cupiditate commodi eligendi rerum velit. Consectetur qui voluptas nihil natus tempore est molestiae. Adipisci voluptatem minima eaque et doloribus cumque error. Et aut non atque temporibus. Assumenda quibusdam sed eveniet corrupti optio sed. Dolore ipsa corporis nemo neque animi doloribus qui modi. In magni minus earum sint sed. Maiores ut inventore sed sint commodi aliquam. Non est sint et maxime dignissimos harum. Placeat tempore nesciunt et et. Voluptas possimus rerum porro aut veritatis. Nihil cumque vero nesciunt.
Non vel cupiditate voluptatem. Magni et delectus cum voluptate voluptas. Quibusdam sunt quas alias hic nesciunt illo quos. Dolores sit soluta sunt.
Veniam sed cumque ut omnis. Adipisci non ipsum voluptatem quo assumenda qui dolorem. Ut ea eius ut ab. Et in quis praesentium earum assumenda enim officiis.
Voluptatem quam omnis ipsa fuga quibusdam fugit facilis. Fuga est non nostrum quasi itaque blanditiis repellendus. Laboriosam veritatis illo et est pariatur sint reprehenderit. Modi dignissimos omnis itaque nesciunt omnis qui non.
Perspiciatis omnis temporibus nisi earum eveniet aperiam beatae. Quo nisi facilis voluptas eligendi. Quisquam ut dolorem et voluptatibus rem maiores velit. Similique excepturi dolorem inventore nam quae esse porro.
", "views": 294, "published_at": "2012-10-22", @@ -231,8 +231,8 @@ }, { "id": 11, - "post_id": 6, - "author": "Logan Schowalter", + "post_id": 2, + "author": 1234, "body": "I don't want to be?' it asked. 'Oh, I'm not Ada,' she said, 'and see whether it's marked \"poison\" or not'; for she had asked it aloud; and in despair she put her hand on the end of the.", "created_at": "2012-08-05" } diff --git a/package.json b/package.json index 10edbee1..8b087b0c 100644 --- a/package.json +++ b/package.json @@ -66,19 +66,20 @@ "lodash": "^3.8.0", "mocha": "^2.1.0", "mocha-traceur": "^2.1.0", + "ng-annotate-loader": "0.0.2", "ng-annotate-webpack-plugin": "^0.1.2", "ng-file-upload": "^2.2.0", "nginflection": "^1.1.10", "ngtemplate-loader": "^1.3.0", "node-libs-browser": "^0.5.0", "node-sass": "^2.1.1", - "nprogress": "^0.1.6", + "nprogress": "^0.2.0", "numeral": "^1.5.3", "papaparse": "^4.1.1", "rangy": "^1.3.0", "restangular": "^1.5.1", - "sinon": "~1.14.1", "sass-loader": "^0.5.0", + "sinon": "~1.14.1", "style-loader": "^0.12.2", "superagent": "^0.18.2", "textangular": "^1.3.11", diff --git a/src/javascripts/ng-admin/Crud/form/FormController.js b/src/javascripts/ng-admin/Crud/form/FormController.js index 5ccc5cea..d3140b43 100644 --- a/src/javascripts/ng-admin/Crud/form/FormController.js +++ b/src/javascripts/ng-admin/Crud/form/FormController.js @@ -1,137 +1,131 @@ -/*global define*/ - -define(function () { - 'use strict'; - - var FormController = function ($scope, $state, WriteQueries, Configuration, - progression, notification, view, dataStore) { - - this.$scope = $scope; - this.$state = $state; - this.WriteQueries = WriteQueries; - this.dataStore = dataStore; - this.progression = progression; - this.notification = notification; - this.title = view.title(); - this.description = view.description(); - this.actions = view.actions(); - this.fields = view.fields(); - this.config = Configuration(); - this.view = view; - this.entity = this.view.getEntity(); - this.$scope.entry = dataStore.getFirstEntry(this.entity.uniqueId); - this.$scope.view = view; - this.$scope.entity = this.entity; - - // in case of entity identifier being modified - this.originEntityId = this.$scope.entry.values[this.entity.identifier().name()]; - - $scope.$on('$destroy', this.destroy.bind(this)); - }; - - FormController.prototype.validateEntry = function () { - var value, - form = this.form, - entry = this.$scope.entry, - fields = this.view.getFields(), - identifierField = this.entity.identifier(), - mappedObject, - field, - i, - object = {}; - - if (!form.$valid) { - this.notification.log('invalid form', {addnCls: 'humane-flatty-error'}); - return false; - } - - // Inject identifier - object[identifierField.name()] = entry.identifierValue; - - for (i in fields) { - field = fields[i]; - value = entry.values[field.name()]; - object[field.name()] = value; - } - - mappedObject = this.dataStore.mapEntry( - this.view.entity.name(), - this.view.identifier(), - this.view.getFields(), - object - ); - - try { - this.view.validate(mappedObject); - } catch (e) { - this.notification.log(e, {addnCls: 'humane-flatty-error'}); - return false; - } - - return object; - }; - - FormController.prototype.submitCreation = function ($event) { - $event.preventDefault(); - var entry = this.validateEntry(); - var entity = this.entity; - var route = !entity.editionView().enabled ? 'show' : 'edit'; - if (!entry) { - return; - } - var progression = this.progression, - notification = this.notification, - $state = this.$state; - progression.start(); - this.WriteQueries - .createOne(this.view, entry) - .then(function (rawEntry) { - var entry = this.dataStore.mapEntry(entity.name(), this.view.identifier(), this.view.getFields(), rawEntry); - progression.done(); - notification.log('Element successfully created.', {addnCls: 'humane-flatty-success'}); - $state.go($state.get(route), { entity: entity.name(), id: entry.identifierValue }); - }.bind(this), this.handleError.bind(this)); - }; - - FormController.prototype.submitEdition = function ($event) { - $event.preventDefault(); - var entry = this.validateEntry(); - if (!entry) { - return; - } - var progression = this.progression, - notification = this.notification; - progression.start(); - this.WriteQueries - .updateOne(this.view, entry, this.originEntityId) - .then(function () { - progression.done(); - notification.log('Changes successfully saved.', {addnCls: 'humane-flatty-success'}); - }, this.handleError.bind(this)); - }; - - /** - * Handle create or update errors - * - * @param {Object} response - */ - FormController.prototype.handleError = function (response) { - var errorMessage = this.config.getErrorMessageFor(this.view, response); - - this.progression.done(); - this.notification.log(errorMessage, {addnCls: 'humane-flatty-error'}); - }; - - FormController.prototype.destroy = function () { - this.$scope = undefined; - this.$state = undefined; - this.WriteQueries = undefined; - this.dataStore = undefined; - this.view = undefined; - this.entity = undefined; - }; - - FormController.$inject = ['$scope', '$state', 'WriteQueries', 'NgAdminConfiguration', 'progression', 'notification', 'view', 'dataStore']; - - return FormController; -}); +var FormController = function ($scope, $state, WriteQueries, Configuration, + progression, notification, view, dataStore) { + + this.$scope = $scope; + this.$state = $state; + this.WriteQueries = WriteQueries; + this.dataStore = dataStore; + this.progression = progression; + this.notification = notification; + this.title = view.title(); + this.description = view.description(); + this.actions = view.actions(); + this.fields = view.fields(); + this.config = Configuration(); + this.view = view; + this.entity = this.view.getEntity(); + this.$scope.entry = dataStore.getFirstEntry(this.entity.uniqueId); + this.$scope.view = view; + this.$scope.entity = this.entity; + + // in case of entity identifier being modified + this.originEntityId = this.$scope.entry.values[this.entity.identifier().name()]; + + $scope.$on('$destroy', this.destroy.bind(this)); +}; + +FormController.prototype.validateEntry = function () { + var value, + form = this.form, + entry = this.$scope.entry, + fields = this.view.getFields(), + identifierField = this.entity.identifier(), + mappedObject, + field, + i, + object = {}; + + if (!form.$valid) { + this.notification.log('invalid form', {addnCls: 'humane-flatty-error'}); + return false; + } + + // Inject identifier + object[identifierField.name()] = entry.identifierValue; + + for (i in fields) { + field = fields[i]; + value = entry.values[field.name()]; + object[field.name()] = value; + } + + mappedObject = this.dataStore.mapEntry( + this.view.entity.name(), + this.view.identifier(), + this.view.getFields(), + object + ); + + try { + this.view.validate(mappedObject); + } catch (e) { + this.notification.log(e, {addnCls: 'humane-flatty-error'}); + return false; + } + + return object; +}; + +FormController.prototype.submitCreation = function ($event) { + $event.preventDefault(); + var entry = this.validateEntry(); + var entity = this.entity; + var route = !entity.editionView().enabled ? 'show' : 'edit'; + if (!entry) { + return; + } + var progression = this.progression, + notification = this.notification, + $state = this.$state; + progression.start(); + this.WriteQueries + .createOne(this.view, entry) + .then(function (rawEntry) { + var entry = this.dataStore.mapEntry(entity.name(), this.view.identifier(), this.view.getFields(), rawEntry); + progression.done(); + notification.log('Element successfully created.', {addnCls: 'humane-flatty-success'}); + $state.go($state.get(route), { entity: entity.name(), id: entry.identifierValue }); + }.bind(this), this.handleError.bind(this)); +}; + +FormController.prototype.submitEdition = function ($event) { + $event.preventDefault(); + var entry = this.validateEntry(); + if (!entry) { + return; + } + var progression = this.progression, + notification = this.notification; + progression.start(); + this.WriteQueries + .updateOne(this.view, entry, this.originEntityId) + .then(function () { + progression.done(); + notification.log('Changes successfully saved.', {addnCls: 'humane-flatty-success'}); + }, this.handleError.bind(this)); +}; + +/** + * Handle create or update errors + * + * @param {Object} response + */ +FormController.prototype.handleError = function (response) { + var errorMessage = this.config.getErrorMessageFor(this.view, response); + + this.progression.done(); + this.notification.log(errorMessage, {addnCls: 'humane-flatty-error'}); +}; + +FormController.prototype.destroy = function () { + this.$scope = undefined; + this.$state = undefined; + this.WriteQueries = undefined; + this.dataStore = undefined; + this.view = undefined; + this.entity = undefined; +}; + +FormController.$inject = ['$scope', '$state', 'WriteQueries', 'NgAdminConfiguration', 'progression', 'notification', 'view', 'dataStore']; + +module.exports = FormController; diff --git a/src/javascripts/ng-admin/Crud/routing.js b/src/javascripts/ng-admin/Crud/routing.js index 2dc01ae8..dda4759a 100644 --- a/src/javascripts/ng-admin/Crud/routing.js +++ b/src/javascripts/ng-admin/Crud/routing.js @@ -19,8 +19,9 @@ function templateProvider(viewName, defaultView) { function viewProvider(viewName) { return ['$stateParams', 'NgAdminConfiguration', function ($stateParams, Configuration) { + var view; try { - var view = Configuration().getViewByEntityAndType($stateParams.entity, viewName); + view = Configuration().getViewByEntityAndType($stateParams.entity, viewName); } catch (e) { var error404 = new Error('Unknown view or entity name'); error404.status = 404; // trigger the 404 error @@ -33,6 +34,12 @@ function viewProvider(viewName) { }]; } +function dataStoreProvider() { + return ['AdminDescription', function (AdminDescription) { + return AdminDescription.getDataStore(); + }]; +} + function routing($stateProvider) { $stateProvider @@ -50,17 +57,83 @@ function routing($stateProvider) { controllerAs: 'listController', templateProvider: templateProvider('ListView', listTemplate), resolve: { + dataStore: dataStoreProvider(), view: viewProvider('ListView'), - data: ['$stateParams', 'ReadQueries', 'view', function ($stateParams, ReadQueries, view) { + response: ['$stateParams', 'ReadQueries', 'view', function ($stateParams, ReadQueries, view) { var page = $stateParams.page, filters = $stateParams.search, sortField = $stateParams.sortField, sortDir = $stateParams.sortDir; - return ReadQueries.getAll(view, page, true, filters, sortField, sortDir); + return ReadQueries.getAll(view, page, filters, sortField, sortDir); + }], + totalItems: ['response', function (response) { + return response.totalItems; + }], + referencedData: ['ReadQueries', 'view', 'response', function (ReadQueries, view, response) { + return ReadQueries.getReferencedData(view.getReferences(), response.data); + }], + referencedEntries: ['dataStore', 'view', 'referencedData', function (dataStore, view, referencedData) { + var references = view.getReferences(); + var referencedEntries; + + for (var name in referencedData) { + referencedEntries = dataStore.mapEntries( + references[name].targetEntity().name(), + references[name].targetEntity().identifier(), + [references[name].targetField()], + referencedData[name] + ); + + dataStore.setEntries( + references[name].targetEntity().uniqueId + '_values', + referencedEntries + ); + } + + return true; + }], + entries: ['dataStore', 'view', 'response', 'referencedEntries', function (dataStore, view, response, referencedEntries) { + var entries = dataStore.mapEntries( + view.entity.name(), + view.identifier(), + view.getFields(), + response.data + ); + + // shortcut to diplay collection of entry with included referenced values + dataStore.fillReferencesValuesFromCollection(entries, view.getReferences(), true); + + // set entries here ??? + dataStore.setEntries( + view.getEntity().uniqueId, + entries + ); + + return true; + }], + filterData: ['ReadQueries', 'view', function (ReadQueries, view) { + return ReadQueries.getReferencedData(view.getFilterReferences()); }], - referencedValues: ['$stateParams', 'ReadQueries', 'view', function ($stateParams, ReadQueries, view) { - return ReadQueries.getReferencedValues(view.getFilterReferences()); + filterEntries: ['dataStore', 'view', 'filterData', function (dataStore, view, filterData) { + var filters = view.getFilterReferences(); + var filterEntries; + + for (var name in filterData) { + filterEntries = dataStore.mapEntries( + filters[name].targetEntity().name(), + filters[name].targetEntity().identifier(), + [filters[name].targetField()], + filterData[name] + ); + + dataStore.setEntries( + filters[name].targetEntity().uniqueId + '_choices', + filterEntries + ); + } + + return true; }] } }); @@ -79,21 +152,76 @@ function routing($stateProvider) { sortDir: null }, resolve: { + dataStore: dataStoreProvider(), view: viewProvider('ShowView'), rawEntry: ['$stateParams', 'ReadQueries', 'view', function ($stateParams, ReadQueries, view) { - return RetrieveQueries.getOne(view.getEntity(), view.type, $stateParams.id, view.identifier(), view.getUrl()); + return ReadQueries.getOne(view.getEntity(), view.type, $stateParams.id, view.identifier(), view.getUrl()); }], - referencedValues: ['ReadQueries', 'view', 'rawEntry', function (ReadQueries, view, rawEntry) { - return ReadQueries.getReferencedValues(view.getReferences(), [rawEntry.values]); + entry: ['dataStore', 'view', 'rawEntry', function(dataStore, view, rawEntry) { + return dataStore.mapEntry( + view.entity.name(), + view.identifier(), + view.getFields(), + rawEntry + ); }], - referencedListValues: ['$stateParams', 'ReadQueries', 'view', 'rawEntry', function ($stateParams, ReadQueries, view, rawEntry) { - var sortField = $stateParams.sortField, - sortDir = $stateParams.sortDir; + referencedData: ['ReadQueries', 'view', 'entry', function (ReadQueries, view, entry) { + return ReadQueries.getReferencedData(view.getReferences(), [entry.values]); + }], + referencedEntries: ['dataStore', 'view', 'referencedData', function (dataStore, view, referencedData) { + var references = view.getReferences(); + var referencedEntries; + + for (var name in referencedData) { + referencedEntries = dataStore.mapEntries( + references[name].targetEntity().name(), + references[name].targetEntity().identifier(), + [references[name].targetField()], + referencedData[name] + ); + + dataStore.setEntries( + references[name].targetEntity().uniqueId + '_values', + referencedEntries + ); + } + + return true; + }], + referencedListData: ['$stateParams', 'ReadQueries', 'view', 'entry', function ($stateParams, ReadQueries, view, entry) { + var referencedLists = view.getReferencedLists(); + var sortField = $stateParams.sortField; + var sortDir = $stateParams.sortDir; + + return ReadQueries.getReferencedListData(referencedLists, sortField, sortDir, entry.identifierValue); + }], + referencedListEntries: ['dataStore', 'view', 'referencedListData', function (dataStore, view, referencedListData) { + var referencedLists = view.getReferencedLists(); + var referencedList; + var referencedListEntries; - return ReadQueries.getReferencedListValues(view, sortField, sortDir, rawEntry.identifierValue); + for (var i in referencedLists) { + referencedList = referencedLists[i]; + referencedListEntries = referencedListData[i]; + + referencedListEntries = dataStore.mapEntries( + referencedList.targetEntity().name(), + referencedList.targetEntity().identifier(), + referencedList.targetFields(), + referencedListEntries + ); + + dataStore.setEntries( + referencedList.targetEntity().uniqueId + '_list', + referencedListEntries + ); + } }], - entry: ['ReadQueries', 'rawEntry', 'referencedValues', function(ReadQueries, rawEntry, referencedValues) { - return ReadQueries.fillReferencesValuesFromEntry(rawEntry, referencedValues, true); + entryWithReferences: ['dataStore', 'view', 'entry', 'referencedEntries', function(dataStore, view, entry, referencedEntries) { + dataStore.fillReferencesValuesFromEntry(entry, view.getReferences(), true); + + dataStore.addEntry(view.getEntity().uniqueId, entry); + return true; }] } }); @@ -106,17 +234,36 @@ function routing($stateProvider) { controllerAs: 'formController', templateProvider: templateProvider('CreateView', createTemplate), resolve: { + dataStore: dataStoreProvider(), view: viewProvider('CreateView'), - entry: ['view', function (view) { - var entry = view - .mapEntry({}); - - view.processFieldsDefaultValue(entry); + entry: ['dataStore', 'view', function (dataStore, view) { + var entry = dataStore.createEntry(view.entity.name(), view.identifier(), view.getFields()); + dataStore.addEntry(view.getEntity().uniqueId, entry); return entry; }], - referencedValues: ['ReadQueries', 'view', function (ReadQueries, view) { - return ReadQueries.getReferencedValues(view.getReferences()); + referencedData: ['ReadQueries', 'view', function (ReadQueries, view) { + return ReadQueries.getReferencedData(view.getReferences()); + }], + referencedEntries: ['dataStore', 'view', 'referencedData', function (dataStore, view, referencedData) { + var references = view.getReferences(); + var referencedEntries; + + for (var name in referencedData) { + referencedEntries = dataStore.mapEntries( + references[name].targetEntity().name(), + references[name].targetEntity().identifier(), + [references[name].targetField()], + referencedData[name] + ); + + dataStore.setEntries( + references[name].targetEntity().uniqueId + '_choices', + referencedEntries + ); + } + + return true; }] } }); @@ -135,21 +282,76 @@ function routing($stateProvider) { sortDir: null }, resolve: { + dataStore: dataStoreProvider(), view: viewProvider('EditView'), rawEntry: ['$stateParams', 'ReadQueries', 'view', function ($stateParams, ReadQueries, view) { + return ReadQueries.getOne(view.getEntity(), view.type, $stateParams.id, view.identifier(), view.getUrl()); + }], + entry: ['dataStore', 'view', 'rawEntry', function(dataStore, view, rawEntry) { + return dataStore.mapEntry( + view.entity.name(), + view.identifier(), + view.getFields(), + rawEntry + ); + }], + referencedData: ['ReadQueries', 'view', function (ReadQueries, view) { + return ReadQueries.getReferencedData(view.getReferences()); + }], + referencedEntries: ['dataStore', 'view', 'referencedData', function (dataStore, view, referencedData) { + var references = view.getReferences(); + var referencedEntries; + for (var name in referencedData) { + referencedEntries = dataStore.mapEntries( + references[name].targetEntity().name(), + references[name].targetEntity().identifier(), + [references[name].targetField()], + referencedData[name] + ); + + dataStore.setEntries( + references[name].targetEntity().uniqueId + '_choices', + referencedEntries + ); + } + + return true; }], - referencedValues: ['ReadQueries', 'view', 'rawEntry', function (ReadQueries, view, rawEntry) { - return ReadQueries.getReferencedValues(view.getReferences(), null); + referencedListData: ['$stateParams', 'ReadQueries', 'view', 'entry', function ($stateParams, ReadQueries, view, entry) { + var referencedLists = view.getReferencedLists(); + var sortField = $stateParams.sortField; + var sortDir = $stateParams.sortDir; + + return ReadQueries.getReferencedListData(referencedLists, sortField, sortDir, entry.identifierValue); }], - referencedListValues: ['$stateParams', 'ReadQueries', 'view', 'rawEntry', function ($stateParams, ReadQueries, view, rawEntry) { - var sortField = $stateParams.sortField, - sortDir = $stateParams.sortDir; + referencedListEntries: ['dataStore', 'view', 'referencedListData', function (dataStore, view, referencedListData) { + var referencedLists = view.getReferencedLists(); + var referencedList; + var referencedListEntries; + + for (var i in referencedLists) { + referencedList = referencedLists[i]; + referencedListEntries = referencedListData[i]; + + referencedListEntries = dataStore.mapEntries( + referencedList.targetEntity().name(), + referencedList.targetEntity().identifier(), + referencedList.targetFields(), + referencedListEntries + ); - return ReadQueries.getReferencedListValues(view, sortField, sortDir, rawEntry.identifierValue); + dataStore.setEntries( + referencedList.targetEntity().uniqueId + '_list', + referencedListEntries + ); + } }], - entry: ['ReadQueries', 'rawEntry', 'referencedValues', function(ReadQueries, rawEntry, referencedValues) { - return ReadQueries.fillReferencesValuesFromEntry(rawEntry, referencedValues, true); + entryWithReferences: ['dataStore', 'view', 'entry', 'referencedEntries', function(dataStore, view, entry, referencedEntries) { + dataStore.fillReferencesValuesFromEntry(entry, view.getReferences(), true); + + dataStore.addEntry(view.getEntity().uniqueId, entry); + return true; }] } }); @@ -167,7 +369,7 @@ function routing($stateProvider) { return $stateParams; }], entry: ['$stateParams', 'ReadQueries', 'view', function ($stateParams, ReadQueries, view) { - + return ReadQueries.getOne(view.getEntity(), view.type, $stateParams.id, view.identifier(), view.getUrl()); }] } }); diff --git a/webpack.config.js b/webpack.config.js index 4deedd02..0386c642 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,4 +1,3 @@ -var ngAnnotatePlugin = require('ng-annotate-webpack-plugin'); var ExtractTextPlugin = require('extract-text-webpack-plugin'); var sources = [ @@ -6,6 +5,12 @@ var sources = [ 'bootstrap-sass/assets/stylesheets/_bootstrap.scss', './src/sass/ng-admin.scss', + 'nprogress/nprogress.css', + 'humane-js/themes/flatty.css', + 'textangular/src/textAngular.css', + 'codemirror/lib/codemirror.css', + 'codemirror/addon/lint/lint.css', + './src/javascripts/ng-admin.js' ]; @@ -24,19 +29,14 @@ module.exports = { module: { loaders: [ { test: /es6.+\.js$/, loader: 'babel-loader' }, + { test: /\.js/, loader: 'ng-annotate' }, { test: /\.html$/, loader: 'html' }, - { - test: /\.(woff2?|svg|ttf|eot)(\?.*)?$/, - loader: 'file?name=build/assets/[name].[ext]' - }, - { - test: /\.scss$/, - loader: ExtractTextPlugin.extract('css!sass') - } + { test: /\.(woff2?|svg|ttf|eot)(\?.*)?$/, loader: 'url' }, + { test: /\.css$/, loader: ExtractTextPlugin.extract('css') }, + { test: /\.scss$/, loader: ExtractTextPlugin.extract('css!sass') } ] }, plugins: [ - new ngAnnotatePlugin({ add: true }), new ExtractTextPlugin('build/ng-admin.min.css', { allChunks: true })