Remove all existing objects from Aurelia Validate - aurelia

Without going into depth, I need to remove all validation objects from a Validation Controller without having access to those objects outside of the controller. Basically this is to cleanup existing validation objects before adding new ones. It's complex.
Very simply, I need to do this:
this.validationCtrl.removeAllObjects();
One possibility I've attempted is to inspect the validation controller and iterate through its objects property, but I'm unable to correctly access these or give the .removeObject() what it needs.
const validationObjects = this.validationCtrl.objects;
validationObjects.forEach(obj => this.validationCtrl.removeObject(obj));
This also doesn't work.
What is the best way to blindly remove all existing validation controller objects?

The following code works to delete all existing objects from the current controller:
const validationEntries = Array.from(this.validationCtrl.objects);
validationEntries.forEach(([key]) => {
this.validationCtrl.removeObject(key);
});

Related

How The Form Validation Is Done In JHIpster Front End?

I need to modify a form validation because some of the inputs are generated by the system instead of human input, those input fields will be filled in a controller. In other words, its DTO has fewer fields with validation constraints than the entity class. I am investigating
$v.myEntity.$invalid
I have a look at all related typescript files and don't see how it is done. Vue is the framework for the front end. I assume that it is the same for the front end regardless of the Javascript framework.
JHipster + Vue uses vuelidate for form validation. Look for an object called validations near the top of your .component.ts files.
Something like this:
const validations: any = {
testEntity: {
testField: {
required,
},
},
};
For example, to make testField no longer required on the front end, remove required, on that .component.ts and the required keyword on the corresponding input on your .vue file.
Remember to also remove the #NotNull on the entity DTO so it's not rejected, and then you can fill it up with whatever you need on the server side.

Prestashop 1.6 Create Module to Display Carrier Filter

My Prestashop-based site is currently having an override for AdminOrdersController.php, I have placed it in override folder.
From the link provided below, it is perfectly working fine to add a Carrier filter which is not available in Prestashop 1.6 now. I have tried the solution and it is working perfectly.
Reference: Adding carrier filter in Orders page.
Unfortunately, for production site, I have no access to core files and unable to implement as such. Thus, I will need to create a custom module. Do take note that I already have an override in place for AdminOrdersController.php. I would like to tap on this override and insert the filter.
I have managed to create a module and tried placing an override (with the code provided in the URL) in mymodule/override/controller/admin/AdminOrdersController.php with the carrier filter feature.
There has been no changes/effect, I am baffled. Do I need to generate or copy any .tpl file?
Any guidance is greatly appreciated.
Thank you.
While the answer in the linked question works fine the same thing can be achieved with a module alone (no overrides needed).
Admin controllers have a hook for list fields modifications. There are two with the same name however they have different data in their params array.
actionControllernameListingFieldsModifier executes before a filter is applied to list.
actionControllernameListingFieldsModifier executes before data is pulled from DB and list is rendered.
So you can add fields to existing controller list definition like this in your module file:
public function hookActionAdminOrdersListingFieldsModifier($params) {
if (isset($params['select'])) {
$params['select'] .= ', cr.name';
$params['join'] .= ' LEFT JOIN `'._DB_PREFIX_.'carrier` cr ON (cr.`id_carrier` = a.`id_carrier`)';
}
$params['fields']['carrier'] = array(
'title' => $this->l('Carrier'),
'align' => 'text-center',
'filter_key' => 'cr!name'
);
}
Because array data is being passed into $params array by reference you can modify them in your hook and changes persist back to controller. This will append carrier column at the end of list.
It is prestashop best practice to try and solve problems through module hooks and only if there is really no way to do it with hooks, then do it with overrides.
Did you delete /cache/class_index.php ? You have to if you want your override to take effect.
If it still does not work, maybe you can process with the hook called in the AdminOrderControllers method with your new module.

silverstripe 3 - How to add access control to generated data objects?

Good afternoon,
Please let me know if this question is not clear enough, I'll try my best to make as straight-forward as possible.
How can I add access control to objects that are generated by an end-user using my data object?
Example: I have a class that extends a DataObject. Someone logs in the back-end; fills out the form that's generated by the CMS for the data object. A record is then created in the database by the CMS.
I would like to add an access control to that newly created record in the database.
For a code scenario you can take a look at one of my posts: Silverstripe 3 - Unable to implement controller access security from CMS
The only other way I can think of asking this question is: How to Dynamically (or programmatically) create permissions for records that are created by a DataObject extension via the CMS?
Thanks for your assistance.
Update - Sample Code
///>snippet, note it also has a Manager class that extends ModelAdmin which manages this!
class component extends DataObject implements PermissionProvider{
public static $db = array(
'Title' => 'Varchar',
'Description' => 'Text',
'Status' => "Enum('Hidden, Published', 'Hidden')",
'Weight' => 'Int'
);
///All the regular permission checks (overrides), for the interface goes here, etc...
///That is: canView, canDelete, canEdit, canCreate, providePermissions
}
Now, from the back-end an end-user can add components using the Manager Interface that's generated by extending ModelAdmin. How can I add individual permissions to those added components by the end-user?
Thanks.
Update 2
Example: Add Process Data Object that extends ModelAdmin will give you this in the back end
Then, when you click on the generated 'Add Process' button, you'll get this:
Finally, someone fills out the form and clicks on the 'Create' button, which saves the data in the database. That looks like this:
Now, on that record thats created in MySQL I'd like to add granular permissions to that record. Meaning, for every record created I want to be able to Deny/Allow access to it via a Group/Individual, etc.
Is that even possible with the SilverStripe framework? Thanks.
Implement the functions canView, canEdit, canDelete, and/or canCreate on your DataObject.
Each function will return true or false depending on the conditions you set - any conditions, not just what is defined in the CMS.
See the example code on the tutorial site.

Same paginator for every controller in ZF2

I'm writing my first app in ZF2, and I want to create pagination system.
Currently, I have something like this in my controllers:
$pagLimit = $this->params()->fromQuery('limit', 1000);
$pagPage = $this->params()->fromQuery('page', 1);
$orderDir = $this->params()->fromQuery('dir', 'ASC');
$orderBy = $this->params()->fromQuery('column', 'id');
$result = $this->getMapper()->getList($orderDir, $orderBy);
$paginator = new Paginator(new ArrayAdapter($result));
$paginator->setItemCountPerPage($pagLimit);
$paginator->setCurrentPageNumber($pagPage);
I think that my solution is not quite good..
If I want to change e.g. default limit of items per page, I have to modify all my controllers. Also, I have to remember to send two arguments for all mapper methods which are getting lists of data.
My first thought was to use inheritance ("MyController" with methods like: setPaginationParams(), and setPaginator($data)).
Then I would have to remember to invoke "my controller" methods in every controller.
But maybe there is a better way to implement the same paginator for every controller in my module? MVC event? Create custom class and use DI?
What is the best way to implement this functionality?
Could you just give me some hints?
I'm new to ZF2 and OOP concepts. :(
You could always extend the paginator with your own, and have default values set.
You could even just pass in the request object or params object and then let the Paginator internally handle some things for you to save setting up default values etc.

Rails 3 - constructor action in controller?

I need to store a value from the database in a variable, and I need to access this variable from all the actions in my controller.
For example, I have the controller home which has 3 actions:
about
contact
blog
I tried to store the value to a variable in application_controller.rb, but this did not work.
How can I do this?
This is about persistence. To get around the fact website are stateless you persist data by storing it in a cookie. Rails gives you a convenient way of doing this called a session hash.
You can also use the flash hash (This is also a session hash)
At the point where you get the value that you wish to store simply call
session[:some_variable] = some_variable
Then when you want to retrieve that variable just call
some_variable = session[:some_variable]
Replace some_variable with a something that makes sense to you
If you want to do this for all controller actions then a before_filter can be useful
Read here about before_filters http://apidock.com/rails/ActionController/Filters/ClassMethods/before_filter
Do not store large objects or arrays of objects in the session. If you need to keep a reference to an active_record object then store just the ID of the record then you can retrieve that record with a find when you need it
If you want to access to a specific variable in all your controller, just do the following.
Into the application controller :
before_filter :set_my_variables
private
def set_my_variables
#variable = MyModel.find(YOUR_CONDITION)
end
And for instance, in your home controller, you will be able to access to #variable.
Hope this helps.