Does not contain a definition for 'file_src' October CMS - octobercms-plugins

I am currently working at October CMS plugin development, I have a problem with file upload. I put the fileupload type to file_src. When I go to to resource it shows an error like this :
model/resource
fields:
name:
label: Name
type: text
required: true
file_src:
label: Upload
type: fileupload
grade_id:
label: Grade
type: dropdown
emptyOption: Select
showSearch: true
subject_id:
label: Subject
type: dropdown
emptyOption: Select
showSearch: true
type_id:
label: Type
type: dropdown
emptyOption: Select
showSearch: true
How can I fix this error?

I fixed it! We must use $attachOne or $attachMany relation on model
I added following code in Resource.php in models
public $attachOne = [
'file_src' => 'System\Models\File'
];
thats it its working now!

Define the current module the selected control is a file. Mean your
current selected control is as a file and you does not define in your
module that time the backend has confused.
Solution:
public $attachOne = [
'profile_pic' => \System\Models\File::class
];

Related

octobercms api Image path

I want to create API from my plugin but API returns all I need expect image paths. Do you know anyone how to get image paths and return in my API?
In my routes.php I have
<?php
use Mycompany\ArubaPlaces\Models\Places;
Route::get('api/places', function(){
$places = Places::All();
return $places;
});
And this is my modelI have this relation. I need "placeimages" paths in my API:
public $attachMany = [
'placesimages' => 'System\Models\File'
];
fields.yaml
fields:
name:
label: Title
span: auto
required: 1
type: text
slug:
label: Slug
span: auto
preset:
field: name
type: slug
type: text
description:
label: Description
size: small
oc.commentPosition: ''
span: full
type: richeditor
latitude:
label: Latitude
span: auto
required: 1
type: text
longitude:
label: Longitude
span: auto
required: 1
type: text
placesimages:
label: 'Place images'
mode: image
useCaption: true
thumbOptions:
mode: crop
extension: auto
span: full
type: fileupload
active:
label: Aktívne
span: auto
type: switch
1) First option is adding protected $with = ['placesimages']; to your Places model to eager load the desired relationships, here you can add more than one relation by default.
2) You can do the eager loading in your query e.g Places::with('placesimages')->get(); if you do not want to eager load all files by default. Also here with accepts an array of relations.
If you are sure that in your app everytime you query a place you want to fetch the images then go for option one, otherwise, option 2 will only get the images when only you specify it in the query builder.
Read more about eager loading

Adding dynamic column header to ng grid

Hi I want to add some columns dynamically (fetching from server) to the already populated column header,I am able to see the static column but the dynamic column are not updated , but I generate the gridoptions.columndef such that the dynamic columns are appended to it,but,in view its not reflecting.
plunker
Here is a plunker that shows how you can do it:
http://plnkr.co/edit/Ko0H8ZltkpngGodaB936?p=preview
$scope.colDefs1 = [{field: 'name', displayName: 'Name'}, {field:'age', displayName:'Age'}];
$scope.colDefs2 = [{field: 'name', displayName: 'Name'}, {field:'age', displayName:'Age'}, {field:'occupation', displayName:'Occupation'}];
$scope.gridOptions = {
data: 'myData',
columnDefs: 'colDefs1'
};
$scope.addColumns = function(){
$scope.colDefs1 = $scope.colDefs2;
}
See also this link to explain why I did it this way:
https://github.com/angular-ui/ng-grid/issues/128
Update: Here is your plunker with todos.json converted to valid JSON and working:
http://plnkr.co/edit/0eRwaBaOv7xaZbMHvbiR?p=preview

multilingual model attributes in sails js advice

I'm about to start a project that's going to require some attributes on a model to be translated and not sure what the best approach would be.
One option would be to create a JSON type attribute and store the translations as
{
title: [{ "en": "cheese" }, {"de": "Käse"}, {"es": "queso"}, etc... ]
}
but I'm also wondering if would be better to store these values in a separate collection and create an association, then when getting the parent model I could just populate with the appropriate language. So something like
Product Model
module.exports = {
attributes: {
sku: 'string',
values:{
collection: 'productValues',
via: 'product'
}
}
}
Product Values Model
module.exports = {
attributes: {
title: 'string',
body: 'string',
language: 'string',
product:{
model: 'product'
}
}
}
I would just add a JSON for translations to the model.
module.exports = {
attributes: {
defaultValue: 'string',
translations: 'json'
}
}
Then you could simply work with the translation object. Delete translations, add new ones etc.
Model.findById(id).then(function(record){
var translations = record.translations;
translations.en = 'Hello';
delete translations.fr;
Model.update({id: id},{translations: translations}, function(){});
});
(Just an example code, didnt test it)
But if you want 1 translation to work with multiple records than it is insufficient. And then you could create seperate collection for translations and reference records of it as needed.

Propel orm 1.6, symfony 1.4 embeded I18N form

I use propelorm (propel 1.6) plugin and symfony 1.4.20.
I have book table with I18n, and this book have relation with gallery table which also have I18n. I fill all book form fields, added two gallery images, filled all images fields. Click on save - it seems all ok: book fields are ok, first and second image have been uploaded, but only first image have filled i18n fields, second image all i18n fields are empty. What's the prob ?
(there's no redeclared doSave(), save(), bind() and other form methods)
schema:
book:
id: ~
title: { type: varchar(255), required: true }
author: { type: varchar(255), required: true }
description: { type: longvarchar, required: true }
sortable_rank: { type: integer, required: true }
is_active: { type: boolean, default: 1 }
_indexes:
active_sort: [ is_active, sortable_rank ]
_propel_behaviors:
sortable:
rank_column: sortable_rank
i18n:
i18n_columns: [title, description, author]
locale_column: culture
locale_alias: culture
default_locale: en
book_gallery:
id: ~
book_id: { type: integer, foreignTable: book, foreignReference: id, required: true, onDelete: cascade }
title: { type: varchar(255), required: true }
image: { type: varchar(255), required: true }
_propel_behaviors:
i18n:
i18n_columns: [title]
locale_column: culture
locale_alias: culture
default_locale: en
book form:
$languages = LanguageQuery::create()->getAllAsArray(); // returns like array('en' => 'english', ...);
$this->embedI18n(array_keys($languages));
$this->widgetSchema->setLabels($languages);
$this->embedRelation('BookGallery', array(
'title' => 'Application book store list',
'item_pattern' => 'Application book store %index%',
));
book gallery form:
$languages = LanguageQuery::create()->getAllAsArray(); // same as in book form
$this->embedI18n(array_keys($languages));
$this->widgetSchema->setLabels($languages);

jqgrid editable x number formating is inconsisent with format on grid

I've built a grid as the code bellow:
colModel: [
{ name: 'price',
label: 'price',
index: 'price',
jsonmap: 'price',
formatter: 'number',
formatoptions: {decimalSeparator:",", thousandsSeparator: ".", decimalPlaces: 2, defaultValue: '0,00'},
editable: true
}
]
The format of field is correctly on grid, for instance: 10,32, but the form created to edit the field fills one with 10.32 instead of 10,32.
Someone knows why this is going on? Do I need to use properties as edittype and editoptions (this one using formmater and formatoptions) as well? if yes, How I need set up these properties?
I've fixed the problem using the the function afterShowForm to handle the formating of field on form generated from grid.
In fact, I was expecting that jQGrid could do that automatically, i.e, using the configuration provided to column to apply on field generated, or if i could apply the configurion on JSON message, for instance:
editoptons: { formatter = "number", formatteroptions = { .... } ...
anyway, it's working now.

Resources