Skip to content

Commit

Permalink
Replace var by let in es6 scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
manuquentin committed May 15, 2015
1 parent 091099d commit bb09f34
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 104 deletions.
6 changes: 3 additions & 3 deletions src/javascripts/ng-admin/Crud/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ define(function (require) {
resolve: {
dataStore: dataStoreProvider(),
view: viewProvider('ShowView'),
rawEntry: ['$stateParams', 'RetrieveQueries', 'view', function ($stateParams, RetrieveQueries, view) {
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) {
Expand Down Expand Up @@ -289,7 +289,7 @@ define(function (require) {
resolve: {
dataStore: dataStoreProvider(),
view: viewProvider('EditView'),
rawEntry: ['$stateParams', 'RetrieveQueries', 'view', function ($stateParams, RetrieveQueries, view) {
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) {
Expand Down Expand Up @@ -373,7 +373,7 @@ define(function (require) {
params: ['$stateParams', function ($stateParams) {
return $stateParams;
}],
entry: ['$stateParams', 'RetrieveQueries', 'view', function ($stateParams, RetrieveQueries, view) {
entry: ['$stateParams', 'ReadQueries', 'view', function ($stateParams, ReadQueries, view) {
return ReadQueries.getOne(view.getEntity(), view.type, $stateParams.id, view.identifier(), view.getUrl());
}]
}
Expand Down
6 changes: 3 additions & 3 deletions src/javascripts/ng-admin/es6/lib/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Application {
}

defaultErrorMessage(response) {
var body = response.data;
let body = response.data;

if (typeof body === 'object') {
body = JSON.stringify(body);
Expand All @@ -36,7 +36,7 @@ class Application {
}

getRouteFor(entity, viewUrl, viewType, identifierValue, identifierName) {
var baseApiUrl = entity.baseApiUrl() || this.baseApiUrl(),
let baseApiUrl = entity.baseApiUrl() || this.baseApiUrl(),
url = viewUrl || entity.getUrl(viewType, identifierValue, identifierName);

// If the view or the entity don't define the url, retrieve it from the baseURL of the entity or the app
Expand Down Expand Up @@ -138,7 +138,7 @@ class Application {
}

getEntity(entityName) {
var foundEntity = this._entities.filter(e => e.name() === entityName)[0];
let foundEntity = this._entities.filter(e => e.name() === entityName)[0];
if (!foundEntity) {
throw new Error(`Unable to find entity "${entityName}"`);
}
Expand Down
28 changes: 13 additions & 15 deletions src/javascripts/ng-admin/es6/lib/DataStore/DataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ class DataStore {
}

getFirstEntry(name) {
var entries = this.getEntries(name);
let entries = this.getEntries(name);

return entries.length ? entries[0] : null;
}

getChoices(field) {
var identifier = field.targetEntity().identifier().name();
var name = field.targetField().name();
let identifier = field.targetEntity().identifier().name();
let name = field.targetField().name();

return this.getEntries(field.targetEntity().uniqueId + '_choices').map(function(entry) {
return {
Expand All @@ -42,7 +42,7 @@ class DataStore {
}

createEntry(entityName, identifier, fields) {
var entry = new Entry.mapFromRest(entityName, identifier, fields, {});
let entry = new Entry.mapFromRest(entityName, identifier, fields, {});

fields.forEach(function (field) {
entry.values[field.name()] = field.defaultValue();
Expand All @@ -52,7 +52,7 @@ class DataStore {
}

mapEntry(entityName, identifier, fields, restEntry) {
var entry = new Entry.mapFromRest(entityName, identifier, fields, restEntry);
let entry = new Entry.mapFromRest(entityName, identifier, fields, restEntry);

return entry;
}
Expand All @@ -64,17 +64,15 @@ class DataStore {
fillReferencesValuesFromCollection(collection, referencedValues, fillSimpleReference) {
fillSimpleReference = typeof (fillSimpleReference) === 'undefined' ? false : fillSimpleReference;

var i, l;

for (i = 0, l = collection.length; i < l; i++) {
for (let i = 0, l = collection.length; i < l; i++) {
collection[i] = this.fillReferencesValuesFromEntry(collection[i], referencedValues, fillSimpleReference);
}

return collection;
}

fillReferencesValuesFromEntry(entry, referencedValues, fillSimpleReference) {
var reference,
let reference,
referenceField,
choices,
entries,
Expand Down Expand Up @@ -104,13 +102,13 @@ class DataStore {
}

getReferenceChoicesById(field) {
var result = {};
var targetField = field.targetField().name();
var targetIdentifier = field.targetEntity().identifier().name();
var entries = this.getEntries(field.targetEntity().uniqueId + '_values');
let result = {};
let targetField = field.targetField().name();
let targetIdentifier = field.targetEntity().identifier().name();
let entries = this.getEntries(field.targetEntity().uniqueId + '_values');

for (var i = 0, l = entries.length ; i < l ; i++) {
var entry = entries[i];
for (let i = 0, l = entries.length ; i < l ; i++) {
let entry = entries[i];
result[entry.values[targetIdentifier]] = entry.values[targetField];
}

Expand Down
5 changes: 3 additions & 2 deletions src/javascripts/ng-admin/es6/lib/Entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ class Entry {
return new Entry(entityName);
}

var identifierValue = null;
let identifierValue = null;

fields.forEach(function (field) {
var fieldName = field.name();
let fieldName = field.name();

if (fieldName in restEntry) {
restEntry[fieldName] = field.getMappedValue(restEntry[fieldName], restEntry);
}
Expand Down
3 changes: 2 additions & 1 deletion src/javascripts/ng-admin/es6/lib/Field/DateField.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class DateField extends Field {
// in order to convert it back to date, we must remove the timezone, then
// remove hours and minutes
date.setMinutes(date.getMinutes() - date.getTimezoneOffset());
var dateString = date.toJSON();

let dateString = date.toJSON();
return dateString ? dateString.substr(0,10) : null;
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/javascripts/ng-admin/es6/lib/Field/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Field {
map(fn) {
if (!fn) return this._maps;
if (typeof(fn) !== "function") {
var type = typeof(fn);
let type = typeof(fn);
throw new Error(`Map argument should be a function, ${type} given.`);
}

Expand Down Expand Up @@ -122,7 +122,7 @@ class Field {
}

getMappedValue(value, entry) {
for (var i in this._maps) {
for (let i in this._maps) {
value = this._maps[i](value, entry);
}

Expand All @@ -134,7 +134,7 @@ class Field {
return this._validation;
}

for (var property in validation) {
for (let property in validation) {
if (!validation.hasOwnProperty(property)) continue;
if (validation[property] === null) {
delete this._validation[property];
Expand Down
10 changes: 5 additions & 5 deletions src/javascripts/ng-admin/es6/lib/Field/ReferenceField.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ class ReferenceField extends Field {
}

getIdentifierValues(rawValues) {
var results = {};
var identifierName = this._name;
for (var i = 0, l = rawValues.length ; i < l ; i++) {
var identifier = rawValues[i][identifierName];
let results = {};
let identifierName = this._name;
for (let i = 0, l = rawValues.length ; i < l ; i++) {
let identifier = rawValues[i][identifierName];
if (!identifier) {
continue;
}

if (identifier instanceof Array) {
for (var j in identifier) {
for (let j in identifier) {
results[identifier[j]] = true;
}
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ReferencedListField extends ReferenceField {
}

getGridColumns() {
var columns = [];
let columns = [];
for (let i = 0, l = this._targetFields.length ; i < l ; i++) {
let field = this._targetFields[i];
columns.push({
Expand Down
68 changes: 29 additions & 39 deletions src/javascripts/ng-admin/es6/lib/Queries/ReadQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ReadQueries extends Queries {
*/
getAll(view, page, filters, sortField, sortDir) {
page = page || 1;
var url = view.getUrl();
let url = view.getUrl();

return this.getRawValues(view.entity, view.name(), view.type, page, view.perPage(), filters, view.filters(), sortField || view.getSortFieldName(), sortDir || view.sortDir(), url)
.then((values) => {
Expand All @@ -54,15 +54,16 @@ class ReadQueries extends Queries {
* @param {Number} perPage
* @param {Object} filterValues
* @param {Object} filterFields
* @param {String} sortField
* @param {String} sortDir
* @param {String} url
*
* @returns {promise} the entity config & the list of objects
*/
getRawValues(entity, viewName, viewType, page, perPage, filterValues, filterFields, sortField, sortDir, url) {
var params = {};
let params = {};

if (page !== -1 ) {
if (page !== -1) {
params._page = (typeof (page) === 'undefined') ? 1 : parseInt(page, 10);
params._perPage = perPage;
}
Expand All @@ -74,7 +75,7 @@ class ReadQueries extends Queries {

if (filterValues && Object.keys(filterValues).length !== 0) {
params._filters = {};
var filterName;
let filterName;

for (filterName in filterValues) {

Expand Down Expand Up @@ -103,22 +104,16 @@ class ReadQueries extends Queries {
* @returns {promise}
*/
getReferencedData(references, rawValues) {
var getRawValues = this.getRawValues.bind(this),
let getRawValues = this.getRawValues.bind(this),
getOne = this.getOne.bind(this),
referencedData = {},
calls = [],
singleCallFilters,
identifiers,
reference,
targetEntity,
data,
i,
j,
k;
calls = [],
data;

for (i in references) {
reference = references[i];
targetEntity = reference.targetEntity();
let reference = references[i],
targetEntity = reference.targetEntity();

if (!rawValues) {
calls.push(getRawValues(targetEntity, targetEntity.name() + '_ListView', 'listView', 1, reference.perPage(), reference.filters(), {}, reference.sortField(), reference.sortDir()));
Expand All @@ -131,13 +126,13 @@ class ReadQueries extends Queries {

// Check if we should retrieve values with 1 or multiple requests
if (reference.hasSingleApiCall()) {
singleCallFilters = reference.getSingleApiCall(identifiers);
let singleCallFilters = reference.getSingleApiCall(identifiers);
calls.push(getRawValues(targetEntity, targetEntity.name() + '_ListView', 'listView', 1, reference.perPage(), singleCallFilters, {}, reference.sortField(), reference.sortDir()));

continue;
}

for (k in identifiers) {
for (let k in identifiers) {
calls.push(getOne(targetEntity, 'listView', identifiers[k], reference.name()));
}
}
Expand All @@ -149,12 +144,12 @@ class ReadQueries extends Queries {
return {};
}

i = 0;
var response;
let response,
i = 0;

for (j in references) {
reference = references[j];
singleCallFilters = reference.getSingleApiCall(identifiers);
for (let j in references) {
let reference = references[j],
singleCallFilters = reference.getSingleApiCall(identifiers);

// Retrieve entries depending on 1 or many request was done
if (singleCallFilters || !rawValues) {
Expand All @@ -171,7 +166,7 @@ class ReadQueries extends Queries {

data = [];
identifiers = reference.getIdentifierValues(rawValues);
for (k in identifiers) {
for (let k in identifiers) {
response = responses[i++];
if (response.status == 'error') {
// one of the responses failed
Expand Down Expand Up @@ -202,31 +197,26 @@ class ReadQueries extends Queries {
* @returns {promise}
*/
getReferencedListData(referencedLists, sortField, sortDir, entityId) {
var getRawValues = this.getRawValues.bind(this),
calls = [],
referencedList,
targetEntity,
viewName,
filter,
i,
j;
let getRawValues = this.getRawValues.bind(this),
calls = [];

for (i in referencedLists) {
referencedList = referencedLists[i];
filter = {};
let referencedList = referencedLists[i],
targetEntity = referencedList.targetEntity(),
viewName = targetEntity.name() + '_ListView',
filter = {};

filter[referencedList.targetReferenceField()] = entityId;
targetEntity = referencedList.targetEntity();
viewName = targetEntity.name() + '_ListView';
calls.push(getRawValues(targetEntity, viewName, 'listView', 1, referencedList.perPage(), filter, {}, sortField || referencedList.getSortFieldName(), sortDir || referencedList.sortDir()));
}

return this._promisesResolver.allEvenFailed(calls)
.then((responses) => {
j = 0;
let j = 0,
entries = {};

var entries = {};
for (i in referencedLists) {
response = responses[j++];
for (let i in referencedLists) {
let response = responses[j++];
if (response.status == 'error') {
// one of the responses failed
continue;
Expand Down
5 changes: 2 additions & 3 deletions src/javascripts/ng-admin/es6/lib/Queries/WriteQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ class WriteQueries extends Queries {
* @returns {promise}
*/
batchDelete(view, entityIds) {
var deleteOne = this.deleteOne.bind(this);

var promises = entityIds.map(function (id) {
let deleteOne = this.deleteOne.bind(this)
let promises = entityIds.map(function (id) {
return deleteOne(view, id);
});

Expand Down
2 changes: 1 addition & 1 deletion src/javascripts/ng-admin/es6/lib/Utils/stringUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
return text;
}

var f = text.charAt(0).toUpperCase();
let f = text.charAt(0).toUpperCase();
text = f + text.substr(1);

return text.replace(/[-_](.)/g, function (match, group1) {
Expand Down
4 changes: 2 additions & 2 deletions src/javascripts/ng-admin/es6/lib/View/ListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ class ListView extends View {
}

getFilterReferences() {
var result = {};
var lists = this._fields.filter(f => f.type() === 'reference');
let result = {};
let lists = this._fields.filter(f => f.type() === 'reference');
for (let i = 0, c = lists.length ; i < c ; i++) {
let list = lists[i];
result[list.name()] = list;
Expand Down
Loading

0 comments on commit bb09f34

Please sign in to comment.