mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-10-27 16:26:32 +01:00
Various fixes plus support for defaultPath selection when async data
This commit is contained in:
@@ -1504,6 +1504,7 @@ class AdminController extends AdminBaseController
|
|||||||
$payload = [
|
$payload = [
|
||||||
'name' => $file_page ? $file_page->title() : $fileInfo->getFilename(),
|
'name' => $file_page ? $file_page->title() : $fileInfo->getFilename(),
|
||||||
'value' => $file_page ? $file_page->route() : $file_path,
|
'value' => $file_page ? $file_page->route() : $file_path,
|
||||||
|
'item-key' => basename($file_page ? $file_page->route() : $file_path),
|
||||||
'filename' => $fileInfo->getFilename(),
|
'filename' => $fileInfo->getFilename(),
|
||||||
'extension' => $type === 'dir' ? '' : $fileInfo->getExtension(),
|
'extension' => $type === 'dir' ? '' : $fileInfo->getExtension(),
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
|
|||||||
@@ -19,31 +19,13 @@ export class Parents {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
labelKey: 'name',
|
labelKey: 'name',
|
||||||
// defaultPath: this.field.val(),
|
defaultPath: this.field.val(),
|
||||||
createItemContent: function(item) {
|
createItemContent: function(item) {
|
||||||
return Parents.createItemContent(this.config, item);
|
return Parents.createItemContent(this.config, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
|
||||||
this.finder = finder(
|
|
||||||
this.container[0],
|
|
||||||
function(parent, config, callback) {
|
|
||||||
return dataLoad(parent, config, callback);
|
|
||||||
},
|
|
||||||
{
|
|
||||||
labelKey: 'name',
|
|
||||||
// defaultPath: this.field.val(),
|
|
||||||
createItemContent: (config, item) => Parents.createItemContent(config, item)
|
|
||||||
}
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
/* this.finder.on('leaf-selected', (item) => {
|
|
||||||
this.finder.emit('create-column', () => this.createSimpleColumn(item));
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.finder.$emitter.on('leaf-selected', (item) => {
|
this.finder.$emitter.on('leaf-selected', (item) => {
|
||||||
this.finder.emit('create-column', () => this.createSimpleColumn(item));
|
this.finder.emit('create-column', () => this.createSimpleColumn(item));
|
||||||
});
|
});
|
||||||
@@ -110,8 +92,6 @@ export class Parents {
|
|||||||
createSimpleColumn(item) {}
|
createSimpleColumn(item) {}
|
||||||
|
|
||||||
dataLoad(parent, callback) {
|
dataLoad(parent, callback) {
|
||||||
console.log(this, parent, callback);
|
|
||||||
|
|
||||||
if (!parent) {
|
if (!parent) {
|
||||||
return callback(this.data);
|
return callback(this.data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ export const DEFAULTS = {
|
|||||||
valueKey: 'value', // new
|
valueKey: 'value', // new
|
||||||
childKey: 'children',
|
childKey: 'children',
|
||||||
iconKey: 'icon', // new
|
iconKey: 'icon', // new
|
||||||
|
itemKey: 'item-key', // new
|
||||||
className: {
|
className: {
|
||||||
container: 'fjs-container',
|
container: 'fjs-container',
|
||||||
col: 'fjs-col',
|
col: 'fjs-col',
|
||||||
@@ -58,7 +59,6 @@ class Finder {
|
|||||||
createColumn(data, parent) {
|
createColumn(data, parent) {
|
||||||
const callback = (data) => this.createColumn(data, parent);
|
const callback = (data) => this.createColumn(data, parent);
|
||||||
|
|
||||||
console.log(typeof data);
|
|
||||||
if (typeof data === 'function') {
|
if (typeof data === 'function') {
|
||||||
data.call(this, parent, callback);
|
data.call(this, parent, callback);
|
||||||
} else if (Array.isArray(data) || typeof data === 'object') {
|
} else if (Array.isArray(data) || typeof data === 'object') {
|
||||||
@@ -174,16 +174,21 @@ class Finder {
|
|||||||
path = Array.isArray(path) ? path : path.split('/').map(bit => bit.trim()).filter(Boolean);
|
path = Array.isArray(path) ? path : path.split('/').map(bit => bit.trim()).filter(Boolean);
|
||||||
|
|
||||||
if (path.length) {
|
if (path.length) {
|
||||||
this.container.children().each((index, child) => $(child).remove);
|
this.container.children().each((index, child) => $(child).remove());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.selectPath(path, data);
|
if (typeof data === 'function') {
|
||||||
|
data.call(this, null, (data) => this.selectPath(path, data));
|
||||||
|
} else {
|
||||||
|
this.selectPath(path, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
selectPath(path, data, column) {
|
selectPath(path, data, column) {
|
||||||
column = column || this.createColumn(data);
|
column = column || this.createColumn(data);
|
||||||
|
|
||||||
const current = path[0];
|
const current = path[0];
|
||||||
const children = data.find((item) => item[this.config.labelKey] === current);
|
const children = data.find((item) => item[this.config.itemKey] === current);
|
||||||
const newColumn = this.itemSelected({
|
const newColumn = this.itemSelected({
|
||||||
column,
|
column,
|
||||||
item: column.find(`[data-fjs-item="${current}"]`).first()
|
item: column.find(`[data-fjs-item="${current}"]`).first()
|
||||||
@@ -244,7 +249,7 @@ class Finder {
|
|||||||
|
|
||||||
listItem.addClass(listItemClasses.join(' '));
|
listItem.addClass(listItemClasses.join(' '));
|
||||||
listItem.append(link)
|
listItem.append(link)
|
||||||
.attr('data-fjs-item', item[this.config.labelKey]);
|
.attr('data-fjs-item', item[this.config.itemKey]);
|
||||||
|
|
||||||
listItem[0]._item = item;
|
listItem[0]._item = item;
|
||||||
|
|
||||||
|
|||||||
18
themes/grav/js/admin.min.js
vendored
18
themes/grav/js/admin.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user