Skip to content

Commit

Permalink
Use Entry mapping capacities from Entry, not DataStore
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto committed Jul 7, 2015
1 parent 2bad0aa commit 079ccd3
Showing 1 changed file with 51 additions and 39 deletions.
90 changes: 51 additions & 39 deletions src/javascripts/ng-admin/Crud/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ function dataStoreProvider() {
}];
}


function entryConstructorProvider() {
return ['AdminDescription', function (AdminDescription) {
return AdminDescription.getEntryConstructor();
}];
}

function routing($stateProvider) {

$stateProvider
Expand All @@ -56,6 +63,7 @@ function routing($stateProvider) {
templateProvider: templateProvider('ListView', listLayoutTemplate),
resolve: {
dataStore: dataStoreProvider(),
Entry: entryConstructorProvider(),
view: viewProvider('ListView'),
filterData: ['ReadQueries', 'view', function (ReadQueries, view) {
return ReadQueries.getAllReferencedData(view.getFilterReferences(false));
Expand All @@ -65,11 +73,11 @@ function routing($stateProvider) {
var filterEntries;

for (var name in filterData) {
filterEntries = dataStore.mapEntries(
filters[name].targetEntity().name(),
filters[name].targetEntity().identifier(),
filterEntries = Entry.createArrayFromRest(
filterData[name],
[filters[name].targetField()],
filterData[name]
filters[name].targetEntity().name(),
filters[name].targetEntity().identifier().name()
);

dataStore.setEntries(
Expand Down Expand Up @@ -98,6 +106,7 @@ function routing($stateProvider) {
template: listTemplate,
resolve: {
dataStore: dataStoreProvider(),
Entry: entryConstructorProvider(),
view: viewProvider('ListView'),
response: ['$stateParams', 'ReadQueries', 'view', function ($stateParams, ReadQueries, view) {
var page = $stateParams.page,
Expand All @@ -116,17 +125,17 @@ function routing($stateProvider) {
optimizedReferencedData: ['ReadQueries', 'view', 'response', function (ReadQueries, view, response) {
return ReadQueries.getOptimizedReferencedData(view.getOptimizedReferences(), response.data);
}],
referencedEntries: ['dataStore', 'view', 'nonOptimizedReferencedData', 'optimizedReferencedData', function (dataStore, view, nonOptimizedReferencedData, optimizedReferencedData) {
referencedEntries: ['dataStore', 'Entry', 'view', 'nonOptimizedReferencedData', 'optimizedReferencedData', function (dataStore, Entry, view, nonOptimizedReferencedData, optimizedReferencedData) {
var references = view.getReferences(),
referencedData = angular.extend(nonOptimizedReferencedData, optimizedReferencedData),
referencedEntries;

for (var name in referencedData) {
referencedEntries = dataStore.mapEntries(
references[name].targetEntity().name(),
references[name].targetEntity().identifier(),
referencedEntries = Entry.createArrayFromRest(
referencedData[name],
[references[name].targetField()],
referencedData[name]
references[name].targetEntity().name(),
references[name].targetEntity().identifier().name()
);

dataStore.setEntries(
Expand Down Expand Up @@ -173,6 +182,7 @@ function routing($stateProvider) {
},
resolve: {
dataStore: dataStoreProvider(),
Entry: entryConstructorProvider(),
view: viewProvider('ShowView'),
rawEntry: ['$stateParams', 'ReadQueries', 'view', function ($stateParams, ReadQueries, view) {
return ReadQueries.getOne(view.getEntity(), view.type, $stateParams.id, view.identifier(), view.getUrl());
Expand All @@ -186,17 +196,17 @@ function routing($stateProvider) {
optimizedReferencedData: ['ReadQueries', 'view', 'entry', function (ReadQueries, view, entry) {
return ReadQueries.getOptimizedReferencedData(view.getOptimizedReferences(), [entry.values]);
}],
referencedEntries: ['dataStore', 'view', 'nonOptimizedReferencedData', 'optimizedReferencedData', function (dataStore, view, nonOptimizedReferencedData, optimizedReferencedData) {
referencedEntries: ['dataStore', 'Entry', 'view', 'nonOptimizedReferencedData', 'optimizedReferencedData', function (dataStore, Entry, view, nonOptimizedReferencedData, optimizedReferencedData) {
var references = view.getReferences(),
referencedData = angular.extend(nonOptimizedReferencedData, optimizedReferencedData),
referencedEntries;

for (var name in referencedData) {
referencedEntries = dataStore.mapEntries(
references[name].targetEntity().name(),
references[name].targetEntity().identifier(),
referencedEntries = Entry.createArrayFromRest(
referencedData[name],
[references[name].targetField()],
referencedData[name]
references[name].targetEntity().name(),
references[name].targetEntity().identifier()
);

dataStore.setEntries(
Expand All @@ -214,7 +224,7 @@ function routing($stateProvider) {

return ReadQueries.getReferencedListData(referencedLists, sortField, sortDir, entry.identifierValue);
}],
referencedListEntries: ['dataStore', 'view', 'referencedListData', function (dataStore, view, referencedListData) {
referencedListEntries: ['dataStore', 'Entry', 'view', 'referencedListData', function (dataStore, Entry, view, referencedListData) {
var referencedLists = view.getReferencedLists();
var referencedList;
var referencedListEntries;
Expand All @@ -223,11 +233,11 @@ function routing($stateProvider) {
referencedList = referencedLists[i];
referencedListEntries = referencedListData[i];

referencedListEntries = dataStore.mapEntries(
referencedList.targetEntity().name(),
referencedList.targetEntity().identifier(),
referencedListEntries = Entry.createArrayFromRest(
referencedListEntries,
referencedList.targetFields(),
referencedListEntries
referencedList.targetEntity().name(),
referencedList.targetEntity().identifier()
);

dataStore.setEntries(
Expand Down Expand Up @@ -261,6 +271,7 @@ function routing($stateProvider) {
resolve: {
dataStore: dataStoreProvider(),
view: viewProvider('CreateView'),
Entry: entryConstructorProvider(),
entry: ['dataStore', 'view', function (dataStore, view) {
var entry = dataStore.createEntry(view.entity.name(), view.identifier(), view.getFields());
dataStore.addEntry(view.getEntity().uniqueId, entry);
Expand All @@ -270,16 +281,16 @@ function routing($stateProvider) {
choiceData: ['ReadQueries', 'view', function (ReadQueries, view) {
return ReadQueries.getAllReferencedData(view.getReferences(false));
}],
choiceEntries: ['dataStore', 'view', 'choiceData', function (dataStore, view, filterData) {
choiceEntries: ['dataStore', 'Entry', 'view', 'choiceData', function (dataStore, Entry, view, filterData) {
var choices = view.getReferences(false);
var choiceEntries;

for (var name in filterData) {
choiceEntries = dataStore.mapEntries(
choices[name].targetEntity().name(),
choices[name].targetEntity().identifier(),
choiceEntries = Entry.createArrayFromRest(
filterData[name],
[choices[name].targetField()],
filterData[name]
choices[name].targetEntity().name(),
choices[name].targetEntity().identifier()
);

dataStore.setEntries(
Expand Down Expand Up @@ -310,6 +321,7 @@ function routing($stateProvider) {
},
resolve: {
dataStore: dataStoreProvider(),
Entry: entryConstructorProvider(),
view: viewProvider('EditView'),
rawEntry: ['$stateParams', 'ReadQueries', 'view', function ($stateParams, ReadQueries, view) {
return ReadQueries.getOne(view.getEntity(), view.type, $stateParams.id, view.identifier(), view.getUrl());
Expand All @@ -323,17 +335,17 @@ function routing($stateProvider) {
optimizedReferencedData: ['ReadQueries', 'view', 'entry', function (ReadQueries, view, entry) {
return ReadQueries.getOptimizedReferencedData(view.getOptimizedReferences(), [entry.values]);
}],
referencedEntries: ['dataStore', 'view', 'nonOptimizedReferencedData', 'optimizedReferencedData', function (dataStore, view, nonOptimizedReferencedData, optimizedReferencedData) {
referencedEntries: ['dataStore', 'Entry', 'view', 'nonOptimizedReferencedData', 'optimizedReferencedData', function (dataStore, Entry, view, nonOptimizedReferencedData, optimizedReferencedData) {
var references = view.getReferences(),
referencedData = angular.extend(nonOptimizedReferencedData, optimizedReferencedData),
referencedEntries;

for (var name in referencedData) {
referencedEntries = dataStore.mapEntries(
references[name].targetEntity().name(),
references[name].targetEntity().identifier(),
referencedEntries = Entry.createArrayFromRest(
referencedData[name],
[references[name].targetField()],
referencedData[name]
references[name].targetEntity().name(),
references[name].targetEntity().identifier()
);

dataStore.setEntries(
Expand All @@ -351,7 +363,7 @@ function routing($stateProvider) {

return ReadQueries.getReferencedListData(referencedLists, sortField, sortDir, entry.identifierValue);
}],
referencedListEntries: ['dataStore', 'view', 'referencedListData', function (dataStore, view, referencedListData) {
referencedListEntries: ['dataStore', 'Entry', 'view', 'referencedListData', function (dataStore, Entry, view, referencedListData) {
var referencedLists = view.getReferencedLists();
var referencedList;
var referencedListEntries;
Expand All @@ -360,11 +372,11 @@ function routing($stateProvider) {
referencedList = referencedLists[i];
referencedListEntries = referencedListData[i];

referencedListEntries = dataStore.mapEntries(
referencedList.targetEntity().name(),
referencedList.targetEntity().identifier(),
referencedListEntries = Entry.createArrayFromRest(
referencedListEntries,
referencedList.targetFields(),
referencedListEntries
referencedList.targetEntity().name(),
referencedList.targetEntity().identifier()
);

dataStore.setEntries(
Expand All @@ -382,16 +394,16 @@ function routing($stateProvider) {
choiceData: ['ReadQueries', 'view', function (ReadQueries, view) {
return ReadQueries.getAllReferencedData(view.getReferences(false));
}],
choiceEntries: ['dataStore', 'view', 'choiceData', function (dataStore, view, filterData) {
choiceEntries: ['dataStore', 'Entry', 'view', 'choiceData', function (dataStore, Entry, view, filterData) {
var choices = view.getReferences(false);
var choiceEntries;

for (var name in filterData) {
choiceEntries = dataStore.mapEntries(
choices[name].targetEntity().name(),
choices[name].targetEntity().identifier(),
choiceEntries = Entry.createArrayFromRest(
filterData[name],
[choices[name].targetField()],
filterData[name]
choices[name].targetEntity().name(),
choices[name].targetEntity().identifier()
);

dataStore.setEntries(
Expand Down

0 comments on commit 079ccd3

Please sign in to comment.