Single Selection on dijit.Tree

You have always wondered how to disable multi-selection on a dijit.Tree?

Search no longer! You have found a solution!

All you need to do is to add the singular property to your tree properties and dndParams :
dndParams: [“onDndDrop”,”itemCreator”,”onDndCancel”,”checkAcceptance”, “checkItemAcceptance”, “dragThreshold”, “betweenThreshold”, “singular”],
singular : true

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html>
<html >
<head>

    <link rel="stylesheet" href="/_static/dojo/../dijit/themes/claro/claro.css">
   
<script src='/_static/dojo/../dojo/dojo.js' data-dojo-config='async: true'></script><script>require([
    "dojo/ready", "dojo/_base/window", "dojo/store/Memory",
    "dijit/tree/ObjectStoreModel", "dijit/Tree"
], function(ready, win, Memory, ObjectStoreModel, Tree){

    // Create test store, adding the getChildren() method required by ObjectStoreModel
    var myStore = new Memory({
        data: [
            { id: 'world', name:'The earth', type:'planet', population: '6 billion'},
            { id: 'AF', name:'Africa', type:'continent', population:'900 million', area: '30,221,532 sq km',
                    timezone: '-1 UTC to +4 UTC', parent: 'world'},
                { id: 'EG', name:'Egypt', type:'country', parent: 'AF' },
                { id: 'KE', name:'Kenya', type:'country', parent: 'AF' },
                    { id: 'Nairobi', name:'Nairobi', type:'city', parent: 'KE' },
                    { id: 'Mombasa', name:'Mombasa', type:'city', parent: 'KE' },
                { id: 'SD', name:'Sudan', type:'country', parent: 'AF' },
                    { id: 'Khartoum', name:'Khartoum', type:'city', parent: 'SD' },
            { id: 'AS', name:'Asia', type:'continent', parent: 'world' },
                { id: 'CN', name:'China', type:'country', parent: 'AS' },
                { id: 'IN', name:'India', type:'country', parent: 'AS' },
                { id: 'RU', name:'Russia', type:'country', parent: 'AS' },
                { id: 'MN', name:'Mongolia', type:'country', parent: 'AS' },
            { id: 'OC', name:'Oceania', type:'continent', population:'21 million', parent: 'world'},
            { id: 'EU', name:'Europe', type:'continent', parent: 'world' },
                { id: 'DE', name:'Germany', type:'country', parent: 'EU' },
                { id: 'FR', name:'France', type:'country', parent: 'EU' },
                { id: 'ES', name:'Spain', type:'country', parent: 'EU' },
                { id: 'IT', name:'Italy', type:'country', parent: 'EU' },
            { id: 'NA', name:'North America', type:'continent', parent: 'world' },
            { id: 'SA', name:'South America', type:'continent', parent: 'world' }
        ],
        getChildren: function(object){
            return this.query({parent: object.id});
        }
    });

    // Create the model
    var myModel = new ObjectStoreModel({
        store: myStore,
        query: {id: 'world'}
    });

    // Create the Tree.   Note that all widget creation should be inside a dojo.ready().
    ready(function(){
        var tree = new Tree({
            model: myModel,
            dndParams: ["onDndDrop","itemCreator","onDndCancel","checkAcceptance", "checkItemAcceptance", "dragThreshold", "betweenThreshold", "singular"],
            singular : true
        });
        tree.placeAt(win.body());
    });
});</script>
</head>
<body class="claro">
   
</body>
</html>

Share and Enjoy

Posted in Dojo | Tagged , , , , | Leave a comment

Continuous Deployment part 2

I have setup Jenkins now to create a Diamond Shaped Project.
This means i Have a Starting job, several Downstream Jobs and a Finishing Job which aggregates all the results.

I will show you step by step what i have done to achieve this.

Here is a list of plugins which i have installed.

Jenkins GIT Plugin
Config File Provider Plugin
Build Pipeline Plugin
Copy+Artifact+Plugin
Join Plugin
Chuck Norris build Facts!
EnvInject Plugin
Build Name Setter Plugin

We will need to create opt-in Branches as we do not want every push to go through the automated build Cycle.
For this i have followed this tutorial

Setup GIT to be used within jenkins.Navigate to manage Jenkins and follow the settings.

Just Setting where it shall find the git executable.


Setting git globals to recognize Jenkins as a comitter

Once we have this set we can go ahead and create our First Job.

My first job just Downloads and Install Dependencies by using Composer.
This is a new Package Manager which in my opinion is really good. One problem i had here is that every time this job starts, composer would check if new updates have to be installed. I prevented this by creating a small script which checks if the composer.lock file has changed within the repository. You can find this script here

My Project Settings:

Set Project Name

Set Parameters as described in the tutorial earlier for Opt-In Branches

Advanced Project Options

I want all my Pipeline jobs to finish before this Job can start again.

Source Code Management

The url to my repository e.g. ssh://jenkins@gitrepos.com/Project.git

Hit the second advanced before Repository Browser.
I want my branches to be merged on to the master before attempting to build

Optional: Add a gitweb url to see changes in the build information

Build Triggers

Set an Authentication Token as described in Opt-In branches

Build Environment
Here we have some more interesting options. In my earlier post i mentioned that we are using PHING. We have a build.properties file which we do not want to have in the scm as it is unique for every Build or workstation.

I have created multiple Configuration files using the Config File Provider Plugin.
In the section “Manage Jenkins” you should find Managed files if you have installed the plugin.

I am creating different Configurations and saving it as a global configuration file which can be used within any Jenkins job.

Select which configuration file you want to use in this section and in my case i needed to create the build.properties file within the workspace so i let Jenkins copy it to the target “build.properties”. This makes it easier for future slave configuration as you do not have to mess with the workspace using ssh or anything later. Jenkins just handles everything.

The next option “Set Build name” is from the “Build Name Setter Plugin” as when viewing Jenkins you only see a build number, but if multiple people start a build process and everyone is in a queue, no one really knows which branch is currently building or going to be built next. Sadly this does not resolve the problem to see who is next in the queue but makes it easier to identify which branch is currently in progress. I added ${GIT_BRANCH) which is an existing environment variable.

Build
Here i just execute the script i mentioned earlier to start a package update.
Select “Add BuildStep” -> “Execute Shell”

Here we add our downstream jobs to be executed
Select “Trigger/call builds on other projects”

Post-build Actions
Specify the Job which shall run after every downstream Job is completed. This is where i aggregate all my results to get the big picture of what is going on in the Project.

Editable Email notification – here i set who gets the email on which build status. Mostly i just set here to only notify on failure as we do not want to be spammed with mails.

Phew, that was a lot of writing already. Will continue the next job tomorrow. Stay tuned!

Share and Enjoy

Posted in Methodology | Tagged , , , , | Leave a comment

My Journey in Continuous Deployment

Hello, I am rather new to the world of blogging so bare with me.

This will be a series of blogs about Continuous Deployment and how to get there. I will be writing about problems which I am facing and what I am experimenting with.

The target of this is to implement a fully automated system which continuously integrates and deploys our development to production servers.

Our main tool we use for this is Jenkins. If you are not familiar with this. Please have a look. It has lot of plugins which can help you implement automated strategies.

So, where am I at the moment?

We are fairly new at using git and are currently discussing viable options on how to implement a successful strategy for git.

Currently I have implemented the solution given here

This solution is great, all the branches are tracked and tested against the master branch.
But… this provides us with another problem… What if we do not want every branch to be tested directly or tested against the master branch?

For this I am currently looking at opt-in branches by using a configuration file as described here

What I find interesting in this approach is that I could also modify it to use different jobs within Jenkins by adding parameters in the config file.
More about this later as I am not sure which approach I would be finally taking.

So, our branching as described above works and all the branches are automatically pushed to the master. Just that each developer has to wait currently for about 12 minutes to know if anything has failed or is Working as expected.

I like working fast and getting Results fast.

I have been toying around with Jenkins to make things work faster but hitting lot of Road blocks on the way.
As this is a pure php project we are also using phing to create the build.

The first question arises when I look at the build.xml which is one huge build process.

To make the build process faster I need to split this up into tasks which can be run in parallel.
– Cleanup the Workspace
– Initialize the Database
– Run Unit Tests
– Run Integration Tests
– Run Statistic Analysers (PHPMD, Pdepend etc)

I had a look at Creating Downstream jobs within Jenkins. This is an Interesting Approach but does not suit our needs currently.

A downstream job is a job that executes after the Upstream job is completed.

My first attempt was to have a look at the build pipeline plugin. Works great but the Master job is successful even if the Downstream job fails. So I would never really get a fully broken build through the Downstream jobs.

I am going to check today if it is possible by using the Job Join plugin from Jenkins.

As per the information I have gathered I can run another Job after all the Downstream jobs have Completed which would allow me to aggregate all the final Results.

So, I will get started and let you guys know how it ended very soon!

To be Continued… :)

Share and Enjoy

Posted in Methodology | Tagged , , , , , | 1 Comment

Checking dependencies in an AMD style module – How To ?

Hello guys and girls :)

Some of you might have converted their old Javascript Modules to AMD style?
Then you probably encountered this creepy feeling when you wonder if you have set all the necessary dependencies right, if you have not forgotten any or worse… if you haven’t forgotten to remove any… (which would mean loading useless dependencies!)

Let me release you from part this suffering, here is a little tool that will do a certain number of checks for you.
This tool does not claim 100% success, nor does it solve anything, it is merely a pointer to probably missing dependencies, or unused ones.
It does not modify your files, just read them.

The good thing with this tool is that it is not trying to do more than what it has been done for : reading files and reporting suspicions. But it does it fast, and spare you with the pain of reading your files a thousand times :)

You will find the little tool here : Amd-Dependency-Checker
It is coded in PHP so you are expected to have a php interpreter somewhere :)
Feel free to pull req to make it better or propose a port to any other language!

Enjoy,
PEM-

Share and Enjoy

Posted in Dojo, PHP | Tagged , , , , | Leave a comment

Zend Framework 1.x + Doctrine Migrations 2.x – How to ?

Hello everybody!

Hounddog (on irc freenode #dojo) and me have worked hard to make something useful to you!

I’m pretty sure some of you already encountered that situation when you feel like poping your eyes out because of incomplete documentations, or lack of help/support…
If you are reading this, you most likely were about to throw away your computer in anger… Fear not! We will try to save your day :)

Just follow the steps :

1. You can have a look at my repository on github : Doctrine Migration Scripts for Zend Framework support

2. You have now two choices :
– Integrates Migrations into your already existing Doctrine folder, in this path : Doctrine/DBAL/Migrations.
– Use Migrations as Standalone (in that case jump to step xxx).

///////// USING MIGRATIONS INSIDE DOCTRINE FOLDER /////////

3. So now basically you should have something like that :
– Doctrine/DBAl/Migrations
– Doctrine/DBAl/Migrations/Configuration
– Doctrine/DBAl/Migrations/Tools
– Doctrine/DBAl/Migrations/Tools/Console
– Doctrine/DBAl/Migrations/Tools/Console/Command

4. In the scripts directory you should have a file called ZendConfiguration.php (if not something went wrong go back to step 1)

5. If you have zend framework installed and running, with doctrine, you might want to create a file called doctrine.php (or whatever you like if you know already what we are talking about, or you could use the one provided in the scripts folder).

6. doctrine.php should look like that (DO NOT FORGET TO EDIT THE FILE AND CHANGE THE PATHS) :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
// Display errors ?
//ini_set('display_errors', 1);
//error_reporting(E_ALL | E_STRICT);

// Define path to application directory
// DO NOT FORGET TO EDIT
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH','/path/to/your/application');

// Define application environment
defined('APPLICATION_ENV')
    || define(
        'APPLICATION_ENV',
        (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development')
    );


// Ensure library/ is on include_path
// DO NOT FORGET TO EDIT
set_include_path(
    '/path/to/where/your/zend/library/is' . PATH_SEPARATOR .
    '/path/to/Doctrine' . PATH_SEPARATOR .
    get_include_path()
);

// Requiring a batch of Classes we will need for namespacing
use Doctrine\Common\ClassLoader,
    Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper,
    Doctrine\ORM\Version,
    Doctrine\ORM\Tools\Console\ConsoleRunner,
    Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper,
    Symfony\Component\Console\Helper\HelperSet,
    Symfony\Component\Console\Helper\DialogHelper,
    Symfony\Component\Console\Application;

// namespacing migrations commands we will be needing later
use Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand,
    Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand,
    Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand,
    Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand,
    Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand,
    Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand;

// We need the Doctrine ClassLoader to manage autoloading
require_once 'Doctrine/Common/ClassLoader.php';

// Load Doctrine
$classLoader = new ClassLoader('Doctrine');
$classLoader->register();

// Load Symfony tools
$classLoader = new ClassLoader('Symfony', 'Doctrine');
$classLoader->register();

// Load Migration
$classLoader = new ClassLoader('Migrations', 'Doctrine/DBAL/');
$classLoader->register();

// Zend_Application
require_once 'Zend/Application.php';

// Create application
// DO NOT FORGET TO EDIT
$application = new Zend_Application(
    APPLICATION_ENV, '/path/to/application.ini'
);

// Bootstrap
$application->bootstrap();

// loading doctrine resource, sometimes called entityManager
// DO NOT FORGET TO EDIT, set the resource to your entityManager
$em = $application->getBootstrap()->getResource('db');

// Load doctrine helpers
$helperSet = new HelperSet(array(
    'db'     => new ConnectionHelper($em->getConnection()),
    'em'     => new EntityManagerHelper($em),
    'dialog' => new DialogHelper()
));

$cli = new Application('Doctrine Command Line Interface', Version::VERSION);
$cli->setCatchExceptions(true);
$cli->setHelperSet($helperSet);

// We are settign the commands to bypass the configuration process and
// directly use our ZendConfiguration
// Just make sure to load from where the file actually is
require_once('ZendConfiguration.php');
$connexion = $em->getConnection();
$zendConfig = new ZendConfiguration($connexion);

// injecting configurations necessary to our ZendConfiguration
// Pass the Application.ini Parameters to our Configuration
$applicationConfig = new Zend_Config(
    $application->getBootstrap()->getOptions(), true
);
// DO NOT FORGET TO EDIT, if needed
$zendConfig->setConfig($applicationConfig->resources->db->migration);
// Here we just need to put some string because the parameter is not optional
// though will not need it. Just need to call the function
$zendConfig->load('zend');

// Setting up Migrations Commands
$diffCmd = new DiffCommand();
$diffCmd->setMigrationConfiguration($zendConfig);

$executeCmd = new ExecuteCommand();
$executeCmd->setMigrationConfiguration($zendConfig);

$generateCmd = new GenerateCommand();
$generateCmd->setMigrationConfiguration($zendConfig);

$migrateCmd = new MigrateCommand();
$migrateCmd->setMigrationConfiguration($zendConfig);

$statusCmd = new StatusCommand();
$statusCmd->setMigrationConfiguration($zendConfig);

$versionCmd = new VersionCommand();
$versionCmd->setMigrationConfiguration($zendConfig);


// Register migration Commands
$cli->addCommands(array(
    $diffCmd, $executeCmd, $generateCmd, $migrateCmd, $statusCmd, $versionCmd
));

// Register All Doctrine Commands
ConsoleRunner::addCommands($cli);

// Runs console application
$cli->run();

for some more information you might want to check this article : Setting up doctrine 2 cli for zend framework

7. We now have to tweak your Zend Framework application.ini file. Add these few lines :

1
2
3
4
5
6
7
8
9
10
; ------------------------------------------------------------------------------
; Doctrine Migrations Configuration
; ------------------------------------------------------------------------------
resources.db.migration.name = "YourSoft (development) Database Migrations"
resources.db.migration.tableName = "doctrine_migration_versions"
resources.db.migration.namespace = "DoctrineMigrations"
resources.db.migration.directory = APPLICATION_PATH "/path/to/migrationsClass/directory"
;set the following two properties if you want to do manual naming on migration classes
;resources.doctrine.migration.migrations.migration1.version = "20111020071337"
;resources.doctrine.migration.migrations.migration1.class = "DoctrineMigrations\VersionNewMigration"

8. Now, try running from the scripts directory :

1
php doctrine.php list migrations

As a result, you should see the commands available, something like that :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Doctrine Command Line Interface version 2.2.1

Usage:
  [options] command [arguments]

Options:
  --help           -h Display this help message.
  --quiet          -q Do not output any message.
  --verbose        -v Increase verbosity of messages.
  --version        -V Display this program version.
  --ansi              Force ANSI output.
  --no-ansi           Disable ANSI output.
  --no-interaction -n Do not ask any interactive question.

Available commands for the "migration" namespace:
  migrations:diff       Generate a migration by comparing your...
  migrations:execute    Execute a single migration version up or down manually.
  migrations:generate   Generate a blank migration class.
  migrations:migrate    Execute a migration to a specified version...
  migrations:status     View the status of a set of migrations.
  migrations:version    Manually add and delete migration versions...

9. You are now supposed to cry of joy and let a Victory shout be heard by the whole company :)

///////// USING MIGRATIONS STANDALONE /////////
Oh well…
To Be Done Later, I feel sorry for you though…
Jokes asides, you should be able to deal with it even with what explained above :)

Share and Enjoy

Posted in Doctrine, PHP, ZendFramework | 3 Comments