Hello Raffael,
thank you for your answer and sorry for answering so late.
I tried the echo ātestā you suggested. when I am sending a request, I get a
āindex.html:1 Uncaught (in promise) SyntaxError: Unexpected token e in JSON at position 1ā
I think this is because my function expects a JSON to be returned as the result of my request. Am I right ?
Here are some more info about my project :
Here is the āfieldsā structure of my Reference collection :
fields:
creator: {name: "creator", type: "collectionlink", localize: false, options: {ā¦}}
dict_form: {name: "dict_form", type: "text", localize: false, options: Array(0)}
display: {name: "display", type: "text", localize: false, options: Array(0)}
exceptionDetails: {name: "exceptionDetails", type: "repeater", localize: false, options: {ā¦}}
isComplement: {name: "isComplement", type: "boolean", localize: false, options: {ā¦}}
isConsolidated: {name: "isConsolidated", type: "boolean", localize: false, options: {ā¦}}
isException: {name: "isException", type: "repeater", localize: false, options: {ā¦}}
isIAdjective: {name: "isIAdjective", type: "boolean", localize: false, options: {ā¦}}
isNaAdjective: {name: "isNaAdjective", type: "boolean", localize: false, options: {ā¦}}
isPublic: {name: "isPublic", type: "boolean", localize: false, options: {ā¦}}
isStandard: {name: "isStandard", type: "boolean", localize: false, options: {ā¦}}
isUser: {name: "isUser", type: "boolean", localize: false, options: {ā¦}}
japanese: {name: "japanese", type: "repeater", localize: false, options: {ā¦}}
nai_form: {name: "nai_form", type: "text", localize: false, options: Array(0)}
position: {name: "position", type: "text", localize: false, options: Array(0)}
premasu_form: {name: "premasu_form", type: "text", localize: false, options: Array(0)}
publicLists: **<- these are the collectionLink I'd like to modify**
localize: false
name: "publicLists"
options: {link: "List", display: "name", multiple: true, limit: false}
type: "collectionlink"
romaji: {name: "romaji", type: "repeater", localize: false, options: {ā¦}}
ruby: {name: "ruby", type: "repeater", localize: false, options: {ā¦}}
standardLists: **<- these are the collectionLink I'd like to modify**
localize: false
name: "standardLists"
options: {link: "List", display: "name", multiple: true, limit: false}
type: "collectionlink"
ta_form: {name: "ta_form", type: "text", localize: false, options: Array(0)}
te_form: {name: "te_form", type: "text", localize: false, options: Array(0)}
translation: {name: "translation", type: "repeater", localize: true, options: {ā¦}}
Here is the code I use to send my request :
class Request
{
constructor(table, callback, args)
{
this._table = table;
this._callback = callback;
this._args = args;
this._typeUrlArg = "/collections/entries/";
this._url = Request.baseUrl + this._typeUrlArg + Request.token;
this._params = {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
filter: {},
populate: 1, // resolve linked collection items
})
};
Request.token = "?token=XXX";
Request.baseUrl = 'https://XXX/cockpit/api';
}
/**
* executes the request
*/
execute()
{
console.log('request', this._params)
fetch(this.url, this._params)
.then(res => res.json())
.then(res => RequestManager.ResolveCallback(res, this._args));
}
}
class RequestLoadCollection extends Request
{
constructor(table, callback, args)
{
super(table, callback, args);
this._type = "LoadRequest";
this._typeUrlArg = "/collections/entries/";
this._url = Request.baseUrl+this._typeUrlArg+this._table+Request.token;
this._params.body = {filter:{},
populate:1,
populateFilter:{_id:true}}
}
}
Here is my bootstrap.php code :
// fire only on api requests and if populate param is true
if (COCKPIT_API_REQUEST && $app->param('populate', false)) {
// fire only for "Reference" collection
$app->on('collections.find.before.Reference', function($name, &$options) {
// create event to filter populated "repos" collection
$this->on('collections.find.before.List', function($name, &$options) {
// set the fields filter to prevent populating the whole entry
// If no custom filter is set, default to "_id" and "full_name",
// otherwise use the custom filter
$options['fields'] = $this->param('populateFilter', [
'_id' => true,
'name' => true
]);
});
});
}
Here what my request looks like when I log it in the console :
{method: "post", headers: {ā¦}, body: {ā¦}}
body:
filter: {}
populate: 1
populateFilter: {_id: true}
__proto__: Object
headers:
Content-Type: "application/json"
__proto__: Object
method: "post"
__proto__: Object
And finally, here is an extract of the result of my request
entries: Array(888)
[0 ⦠99]
0:
creator: {name: "admin", password: "XXX", email: "XXX", references: "", lists: "", ā¦}
dict_form: ""
display: "å
ļ¼ććļ¼ēļ¼ććļ¼ professeur, instituteur, maĆ®tre"
exceptionDetails: ""
isComplement: false
isConsolidated: false
isException: false
isIAdjective: false
isNaAdjective: false
isPublic: true
isStandard: true
isUser: false
japanese: [{ā¦}]
nai_form: ""
position: "A007"
premasu_form: ""
publicLists: []
romaji: [Array(0)]
ruby: [{ā¦}]
standardLists: Array(1)
0:
creator: {name: "admin", password: "XXX", email: "XXX", references: "", lists: "", ā¦}
description: ""
description_en: null
description_pt: null
isComplement: false
isPublic: true
isStandard: true
isUser: false
lessonNum: "01"
name: "LeƧon 1"
name_en: "Lesson 1"
name_pt: "Lição 1"
references: ""
_by: "5f6c617265363265d20000b0"
_created: 1600942466
_id: "5f6c718234616686190000d5"
_mby: "5f6c617265363265d20000b0"
_modified: 1600942967
__proto__: Object
length: 1
__proto__: Array(0)
ta_form: ""
te_form: ""
translation: [{ā¦}]
type: "Nom"
_by: null
_created: 1600965146
_id: "5f6cca1a62393249e7000351"
_modified
Thank you again for your help, I really appreciate