FacebookTwitterFlickrYoutuberss

Version 4

From Zentyal Linux Small Business Server
Jump to: navigation, search

Index || < Prev | Next >


Version 0.4: preload data

In our current module version, when our users want to enable or disable a module there are two options. If the module row does not yet exist, they have to add the row with the desired configuration. Where the module row already exists, users have to click on the edit -pencil icon- button.

From a UI design perspective, it would be nice to have all the module rows added from the very begining. This way, our users will consistently interact with the table in just one way: clicking on the edit button.

In this new version we will learn how to pre-add rows to a given table.

syncRows() is a method that can be implemented if you wish to add or delete some rows before the actual row identifiers array is returned.

The code in src/EBox/Apache2/Model/Modules.pm will be something like this:

# Method: syncRows
#
#   Overrides <EBox::Model::DataTable::syncRows>
#   to pre-add module rows.
sub syncRows
{
    my ($self, $currentRows)  = @_;

    my @modules = ('ssl', 'info', 'status', 'version');
    my %currentModules = map { $self->row($_)->valueByName('module') => 1 }
                     @{$currentRows};

    # Check if there is any module that has not been added yet
    my @modsToAdd = grep { not exists $currentModules{$_} } @modules;

    return 0 unless (@modsToAdd);

    for my $mod (@modsToAdd) {
        $self->add( module => $mod, enabled => 1 );
    }

    return 1;
}

Let's walk through the above code. @modules contains the apache modules that users will be able to enable from this module. $currentRows contains the row identifiers of the stored rows. Note that we use the module name as the row identifier.

In case we do not have to add any row, we just return 0 to tell the framework that we have not added or removed any row.

Once we have the row, we just add it using EBox::Model::DataTable::add(), we pass it a hash containing every field and its value.

Finally, we return 1 to indicate that we have added new rows.


Index || < Prev | Next >

Template:TracNotice

Personal tools
Namespaces

Variants
Actions

Zentyal Wiki

Zentyal Doc
Navigation
Toolbox