Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

admin-config

Package Overview
Dependencies
Maintainers
2
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

admin-config - npm Package Compare versions

Comparing version 0.1.10 to 0.2.0

lib/Collection.js

41

lib/Application.js
import Menu from './Menu/Menu';
import Collection from './Collection';
import Dashboard from './Dashboard';
import orderElement from "./Utils/orderElement";

@@ -10,2 +12,3 @@

this._menu = null;
this._dashboard = null;
this._layout = false;

@@ -120,2 +123,40 @@ this._header = false;

dashboard(dashboard) {
if (!arguments.length) {
if (!this._dashboard) {
this._dashboard = this.buildDashboardFromEntities();
}
return this._dashboard
}
this._dashboard = dashboard;
return this;
}
buildDashboardFromEntities() {
let dashboard = new Dashboard()
this.entities
.filter(entity => entity.dashboardView().enabled)
.map(entity => {
dashboard.addCollection(entity.name(), entity.dashboardView()); // yep, a collection is a ListView, and so is a DashboardView - forgive this duck typing for BC sake
});
if (!dashboard.hasCollections()) {
// still no collection from dashboardViews, let's use listViews instead
this.entities
.filter(entity => entity.listView().enabled)
.map((entity, index) => {
let collection = new Collection();
let listView = entity.listView()
collection.setEntity(entity);
collection.perPage(listView.perPage())
collection.sortField(listView.sortField())
collection.sortDir(listView.sortDir())
collection.order(index);
// use only the first 3 cols
collection.fields(listView.fields().filter((el, index) => index < 3));
dashboard.addCollection(entity.name(), collection);
});
}
return dashboard;
}
customTemplate(customTemplate) {

@@ -122,0 +163,0 @@ if (!arguments.length) return this._customTemplate;

@@ -29,2 +29,4 @@ import Application from "./Application";

import Menu from './Menu/Menu';
import Collection from './Collection';
import Dashboard from './Dashboard';

@@ -71,2 +73,14 @@ class Factory {

dashboard() {
return new Dashboard();
}
collection(entity) {
let collection = new Collection();
if (entity) {
collection.setEntity(entity);
}
return collection;
}
getDataStore() {

@@ -73,0 +87,0 @@ return new DataStore();

@@ -15,2 +15,3 @@ import Field from "./Field";

this._detailLink = true;
this._refreshDelay = 500;
}

@@ -115,4 +116,10 @@

}
refreshDelay(refreshDelay) {
if (!arguments.length) return this._refreshDelay;
this._refreshDelay = parseInt(refreshDelay);
return this;
}
}
export default ReferenceField;

44

lib/Queries/ReadQueries.js

@@ -87,15 +87,19 @@ import Queries from './Queries'

// Compute filtering
if (filterValues && Object.keys(filterValues).length !== 0) {
params._filters = {};
let filterName;
if (filterValues) {
if (typeof(filterValues) === 'function') {
params._filters = filterValues;
} else if (Object.keys(filterValues).length !== 0) {
params._filters = {};
let filterName;
for (filterName in filterValues) {
if (filterFields.hasOwnProperty(filterName) && filterFields[filterName].hasMaps()) {
Object.assign(params._filters, filterFields[filterName].getMappedValue(filterValues[filterName]));
for (filterName in filterValues) {
if (filterFields.hasOwnProperty(filterName) && filterFields[filterName].hasMaps()) {
Object.assign(params._filters, filterFields[filterName].getMappedValue(filterValues[filterName]));
continue;
continue;
}
// It's weird to not map, but why not.
params._filters[filterName] = filterValues[filterName];
}
// It's weird to not map, but why not.
params._filters[filterName] = filterValues[filterName];
}

@@ -177,3 +181,3 @@ }

*/
getAllReferencedData(references) {
getAllReferencedData(references, search) {
if (!references || !Object.keys(references).length) {

@@ -187,6 +191,18 @@ return this._promisesResolver.empty({});

for (let i in references) {
let reference = references[i],
targetEntity = reference.targetEntity();
let reference = references[i];
let targetEntity = reference.targetEntity();
calls.push(getRawValues(targetEntity, targetEntity.name() + '_ListView', 'listView', 1, reference.perPage(), reference.filters(), {}, reference.sortField(), reference.sortDir()));
var filters = reference.filters();
calls.push(getRawValues(
targetEntity,
targetEntity.name() + '_ListView',
'listView',
1,
reference.perPage(),
typeof(filters) === 'function' ? filters(search) : filters,
null,
reference.sortField(),
reference.sortDir()
));
}

@@ -193,0 +209,0 @@

@@ -104,2 +104,33 @@ import Entry from "../Entry";

hasFields() {
return this.fields.length > 0;
}
removeFields() {
this._fields = [];
return this;
}
getFields() {
return this._fields;
}
getField(fieldName) {
return this._fields.filter(f => f.name() === fieldName)[0];
}
getFieldsOfType(type) {
return this._fields.filter(f => f.type() === type);
}
addField(field) {
if (field.order() === null) {
field.order(this._fields.length, true);
}
this._fields.push(field);
this._fields = this._fields.sort((a, b) => (a.order() - b.order()));
return this;
}
static flatten(arg) {

@@ -183,29 +214,2 @@ if (arg.constructor.name === 'Object') {

removeFields() {
this._fields = [];
return this;
}
getFields() {
return this._fields;
}
getField(fieldName) {
return this._fields.filter(f => f.name() === fieldName)[0];
}
getFieldsOfType(type) {
return this._fields.filter(f => f.type() === type);
}
addField(field) {
if (field.order() === null) {
field.order(this._fields.length, true);
}
this._fields.push(field);
this._fields = this._fields.sort((a, b) => (a.order() - b.order()));
return this;
}
getErrorMessage(response) {

@@ -212,0 +216,0 @@ if (typeof(this._errorMessage) === 'function') {

{
"name": "admin-config",
"version": "0.1.10",
"version": "0.2.0",
"private": false,

@@ -5,0 +5,0 @@ "repository": {

@@ -5,2 +5,4 @@ var assert = require('chai').assert;

import Entity from "../../lib/Entity/Entity";
import Field from "../../lib/Field/Field";
import Dashboard from "../../lib/Dashboard";

@@ -223,3 +225,67 @@ describe('Application', function() {

});
})
});
describe('dashboard()', () => {
it('should return an empty dashboard by default', () => {
let dashboard = new Application().dashboard();
assert.deepEqual(dashboard.collections(), {});
});
it('should serve as a setter', () => {
let dashboard = new Dashboard();
const collection = { IAmAFakeCollection: true };
dashboard.addCollection('foo', collection)
let application = new Application();
application.dashboard(dashboard);
assert.deepEqual(application.dashboard().collections(), { foo: collection });
});
});
describe('buildDashboardFromEntities()', () => {
it('should create a dashboard based on the entity dashboard views', () => {
let application = new Application(),
comment = new Entity('comment'),
post = new Entity('post'),
fields = [
new Field('field1'),
new Field('field2')
];
comment.dashboardView().fields(fields);
post.listView().fields(fields); // should be ignored
application
.addEntity(post)
.addEntity(comment);
let dashboard = application.buildDashboardFromEntities();
assert.property(dashboard.collections(), 'comment');
assert.notProperty(dashboard.collections(), 'post');
let commentCollection = dashboard.collections().comment;
assert.deepEqual(commentCollection.fields(), fields);
});
it('should create a dashboard based on the entity list views if no dashboard views', () => {
let application = new Application(),
comment = new Entity('comment'),
post = new Entity('post'),
fields = [
new Field('field1'),
new Field('field2'),
new Field('field3'),
new Field('field4')
];
comment.listView().fields(fields);
application
.addEntity(post)
.addEntity(comment);
let dashboard = application.buildDashboardFromEntities();
assert.property(dashboard.collections(), 'comment');
assert.notProperty(dashboard.collections(), 'post');
let commentCollection = dashboard.collections().comment;
assert.deepEqual(commentCollection.fields(), fields.filter((el, i) => i < 3));
});
});
});
import Factory from "../../lib/Factory";
import Field from "../../lib/Field/Field";
import Collection from "../../lib/Collection";

@@ -45,2 +46,13 @@ var assert = require('chai').assert;

});
describe('collection()', () => {
it('should return a new Collection with the correct entity', () => {
var factory = new Factory();
var dummyEntity = { name: () => 'foo' };
var collection = factory.collection(dummyEntity);
assert.instanceOf(collection, Collection);
assert.equal(collection.getEntity(), dummyEntity);
assert.equal(collection.name(), 'foo_collection');
})
})
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc