Monday, March 30, 2015

jquery - Angular JS: load custom javascript file in ng-view - Stack Overflow

jquery - Angular JS: load custom javascript file in ng-view - Stack Overflow



With helps of ngRoute a template can be loaded which is containing a script tag which includes the js file contains javascript codes that we wanted to run.
Please take a look the below example for usage:

Thursday, March 12, 2015

Full width slider in prestashop 1.6

Full width slider in prestashop 1.6



In this tutorial i want to show you how easily you can change the way of how homeslider appears in default-bootstrap template inPrestaShop 1.6. As you know default homeslider module is a part of homepage of your shop. It appears right below the main menu. Near the module (on right hand side) you can see two small banners. In this guide i will show you how to remove these banners, and how to change width of slider to 100%.

Full width slider default bootstrap prestashop 1.6


How to change full width to 100%
In guide related to prestashop 1.5: homeslider to top ful width we had to change a lot of things in prestashop files, like stylesheet, like template file and also module core (to support new hook). In prestashop 1.6 we can achieve all of this without touching files. We can do everything in back office with available settings and features. Awesome!

Disable to small banners on the right hand side
First step in our modificaiton: we have to remove two small banners on the right hand side of the main slider. These images are a part of "theme configurator" module and to remove these banners we just have to disable this module. But be aware, don't disable module at all, just disable it in hook named displayTopColumn. In this case go to modules > positions tab in back office. Search there for modules list named displayTopColumn. You will see there two modules (by default there are two modules). Click on edit button near theme configurator and click on "unhook", exactly as i show on image below.

Unhooking theme configurator module from displayTopColumn position
unhook theme configurator for prestashop

After this action two small baners will disappear but they will left blank empty space. So we have to fill this blank space with our slider module. Then it will have full width :) 

Change width of the banner
Go to modules > modules tab and search for "image slider for your homepage" addon. Click on configure button near this module and then - you will be redirected to module configuration page. In the main "settings" form change Max width param value from 799px to 1170px (just type 1170 in this field exactly as i show below). Wondering why 1170? 1170 is a width of the main page container.

changing width of the default home slider module from 799 to 1170
homeslider configuration page prestashop 1.6


Removing banners with width smaller than 1170
Due to the fact that we changed width of the slider window, we have to remove old smaller than 1170px (width) pictures that we uploaded. We have to upload pictures with min-width: 1170px; On screenshot below i show how to remove actual slides. Below the "settings" form (where you changed width of slider) you can manage already uploaded slides. Just hit on delete button like i show:

removing default slides with old small width value (799)
remove slides prestashop 1.6

Upload images with new sizes
If you removed all old slides with wrong width - now it's time to upload new pictures. So, you have to prepare own slides for example in photoshop or other desktop software. Create slides with width at least 1170 and upload them to slider. They will appear as a "full" width slides, like i show on effect image at the bottom of this article. After upload new slides - don't forget to Enable them :) You can download example of image with 1170 width here: download picture

New slide uploaded to website
new slides with correct width


effect of our modifications: full width slider in prestashop 1.6
full width slider in prestashop 1.6

Friday, February 20, 2015

Boban Acimovic Consulting | Joining non-related tables in Propel 1.6

Boban Acimovic Consulting | Joining non-related tables in Propel 1.6



I had this problem few days ago and I couldn’t find any useful information on the Internet. I had to browse through Propel internals to find this out and it would be pity not to share it with others. So let’s start with an example:

$accounts = AccountQuery::create()
->joinWith('Account.AdditionalData')
->addJoin(AdditionalDataPeer::VAL, CountryPeer::ID)
->withColumn('country.name', 'CountryName')
->find();
Someone may ask why Country and Account objects have no relation. Well, this is just an example, but imagine that table AdditionalData contain many different values, so we can’t really make any foreign reference as it would have to reference many different tables, which is not possible. There may be other reasons to use something like this, but anyway let’s explain line by line how it works.

->joinWith('Account.AdditionalData')
This is just normal Propel join where we hydrate the main object with related object data.

->addJoin(AdditionalDataPeer::VAL, CountryPeer::ID)
This is the way how we can define additional join with non-related table. The first value, AdditionalDataPeer::VAL represents the field name in the left table and CountryPeer::Id it’s corresponding field in the right table. These constants are defined in base peer classes. As third parameter here you can define the type of join, but I have used just default (inner join). This works fine except the main object is not hydrated with the related object data. Unfortunately, this is not possible using with() method as with() works only with previous join(). Fortunately, there is another way using:

->withColumn('country.name', 'CountryName')
First parameter here is the real table name concatenated with real column name and the second one is an alias name for this column. You can include as many columns from the related table as you want. It’s probably possible to concatenate some predefined Propel constants for the first parameter, like CountryPeer::TABLE_NAME . ‘.’ . CountryPeer::ID, but I haven’t tried that.
And like the documentation for withColumn() says, you can use this value in the resulting object by method getVirtualColumn():

foreach ($accounts as $account) {
print $account->getVirtualColumn('CountryName') . PHP_EOL;
}
I hope this may help someone :)

javascript - How to make a loading indicator for every asynchronous action (using $q) in an angularjs-app - Stack Overflow

javascript - How to make a loading indicator for every asynchronous action (using $q) in an angularjs-app - Stack Overflow



Although I find it very complicated, unnecessary and probably broken, you could decorate $qand override its defer function.
Every time someone asks for a new defer() it runs your own version which also increments a counter. Before handing out the defer object, you register a finally callback (Angular 1.2.0 only but always may fit, too) to decrement the counter.
Finally, you add a watch to $rootScope to monitor when this counter is greater than 0 (faster than having pendingPromisses in $rootScope and bind like ng-show="pendingPromisses > 0").
app.config(function($provide) {
    $provide.decorator('$q', ['$delegate', '$rootScope', function($delegate, $rootScope) {
      var pendingPromisses = 0;
      $rootScope.$watch(
        function() { return pendingPromisses > 0; }, 
        function(loading) { $rootScope.loading = loading; }
      );
      var $q = $delegate;
      var origDefer = $q.defer;
      $q.defer = function() {
        var defer = origDefer();
        pendingPromisses++;
        defer.promise.finally(function() {
          pendingPromisses--;
        });
        return defer;
      };
      return $q;
    }]);
});
Then, view bound to a scope that inherits from $rootScope can have:
<span ng-show="loading">Loading, please wait</span>
(this won't work in directives with isolate scopes)
See it live here.

Calling Commands Within Commands in Symfony2 | Craft It Online!

Calling Commands Within Commands in Symfony2 | Craft It Online!



I was trying to create a command. The intent goes beyond the exercise as there are some guys already who are trying to setup an entire system from the console. But for now we will just do the command creation. The idea is to call commands within commands and for that we have the following information here which is too simple for our purposes and alsohere where we are told how to call commands within commands but the documentation does not elaborate too much on its uses and interesting applications.
So here I paste the code for a basic command:
<?php
namespace Cordova\CrownBundle\Command;
 
use Symfony\Bundle\FrameworkBundle\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\ArrayInput;
 
class SetupCommand extends Command
{
    protected function configure()
    {
        $this
            ->setName('crown:setup')
            ->setDescription('Crown Setup')
            ->addArgument('yesno', InputArgument::REQUIRED, 'Do you want to fire up setup? (y/n)')
            //->addOption('yell', null, InputOption::VALUE_NONE, 'If set, the task will yell in uppercase letters')
        ;
    }
 
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $yesno = $input->getArgument('yesno');
        if ($yesno == 'y') {
            $text = 'Running setup ... ';
            $command = $this->getApplication()->find('doctrine:fixtures:load');
            $arguments = array(
                //'--force' => true
                ''
            );
            $input = new ArrayInput($arguments);
            $returnCode = $command->run($input, $output);
            if($returnCode == 0) {
                $text .= 'fixtures successfully loaded ...';
            }
 
        } else {
            $text = 'Exiting ...';
        }
 
        /*if ($input->getOption('yell')) {
            $text = strtoupper($text);
        }*/
 
        $output->writeln($text);
    }
}
For now we just are loading the fixtures of our system. Of course this command at the moment is found redundant. However it can be well expanded into something more complex. Thanks for reading. Please consider donating.

Wednesday, December 10, 2014

Full width slider in prestashop 1.6

Full width slider in prestashop 1.6







In this tutorial i want to show you how easily you can change the way of how homeslider appears in default-bootstrap template in PrestaShop 1.6. As you know default homeslider module is a part of homepage of your shop. It appears right below the main menu. Near the module (on right hand side) you can see two small banners. In this guide i will show you how to remove these banners, and how to change width of slider to 100%.

Full width slider default bootstrap prestashop 1.6


How to change full width to 100%
In guide related to prestashop 1.5: homeslider to top ful width we had to change a lot of things in prestashop files, like stylesheet, like template file and also module core (to support new hook). In prestashop 1.6 we can achieve all of this without touching files. We can do everything in back office with available settings and features. Awesome!

Disable to small banners on the right hand side
First step in our modificaiton: we have to remove two small banners on the right hand side of the main slider. These images are a part of "theme configurator" module and to remove these banners we just have to disable this module. But be aware, don't disable module at all, just disable it in hook named displayTopColumn. In this case go to modules > positions tab in back office. Search there for modules list named displayTopColumn. You will see there two modules (by default there are two modules). Click on edit button near theme configurator and click on "unhook", exactly as i show on image below.

Unhooking theme configurator module from displayTopColumn position
unhook theme configurator for prestashop

After this action two small baners will disappear but they will left blank empty space. So we have to fill this blank space with our slider module. Then it will have full width :) 

Change width of the banner
Go to modules > modules tab and search for "image slider for your homepage" addon. Click on configure button near this module and then - you will be redirected to module configuration page. In the main "settings" form change Max width param value from 799px to 1170px (just type 1170 in this field exactly as i show below). Wondering why 1170? 1170 is a width of the main page container.

changing width of the default home slider module from 799 to 1170
homeslider configuration page prestashop 1.6


Removing banners with width smaller than 1170
Due to the fact that we changed width of the slider window, we have to remove old smaller than 1170px (width) pictures that we uploaded. We have to upload pictures with min-width: 1170px; On screenshot below i show how to remove actual slides. Below the "settings" form (where you changed width of slider) you can manage already uploaded slides. Just hit on delete button like i show:

removing default slides with old small width value (799)
remove slides prestashop 1.6

Upload images with new sizes
If you removed all old slides with wrong width - now it's time to upload new pictures. So, you have to prepare own slides for example in photoshop or other desktop software. Create slides with width at least 1170 and upload them to slider. They will appear as a "full" width slides, like i show on effect image at the bottom of this article. After upload new slides - don't forget to Enable them :) You can download example of image with 1170 width here: download picture

New slide uploaded to website
new slides with correct width


effect of our modifications: full width slider in prestashop 1.6
full width slider in prestashop 1.6

php - Propel and leftJoin - unrelated tables - Stack Overflow

php - Propel and leftJoin - Stack Overflow



$results = OneQuery::create()
   ->useTwoQuery(null, Criteria::LEFT_JOIN)
      ->filterByText('aaa')
      ->useThreeQuery(null, Criteria::LEFT_JOIN)
         ->filterByText('bbb')
      ->endUse()
   ->endUse()
->find();

Monday, August 25, 2014

AngularJS sortable table

CodePen - Pen



<section ng-app="app" ng-controller="MainCtrl">

  <span class="label">Ordered By: {{orderByField}}, Reverse Sort: {{reverseSort}}</span><br><br>

  <table class="table table-bordered">

    <thead>

      <tr>

        <th>

          <a href="#" ng-click="orderByField='firstName'; reverseSort = !reverseSort">

          First Name <span ng-show="orderByField == 'firstName'"><span ng-show="!reverseSort">^</span><span ng-show="reverseSort">v</span></span>

          </a>

        </th>

        <th>

          <a href="#" ng-click="orderByField='lastName'; reverseSort = !reverseSort">

            Last Name <span ng-show="orderByField == 'lastName'"><span ng-show="!reverseSort">^</span><span ng-show="reverseSort">v</span></span>

          </a>

        </th>

        <th>

          <a href="#" ng-click="orderByField='age'; reverseSort = !reverseSort">

          Age <span ng-show="orderByField == 'age'"><span ng-show="!reverseSort">^</span><span ng-show="reverseSort">v</span></span>

          </a>

        </th>

      </tr>

    </thead>

    <tbody>

      <tr ng-repeat="emp in data.employees|orderBy:orderByField:reverseSort">

        <td>{{emp.firstName}}</td>

        <td>{{emp.lastName}}</td>

        <td>{{emp.age}}</td>

      </tr>

    </tbody>

  </table>

</section>







var app = angular.module('app', []);



app.controller('MainCtrl', function($scope) {

  $scope.orderByField = 'firstName';

  $scope.reverseSort = false;

 

  $scope.data = {

    employees: [{

      firstName: 'John',

      lastName: 'Doe',

      age: 30

    },{

      firstName: 'Frank',

      lastName: 'Burns',

      age: 54

    },{

      firstName: 'Sue',

      lastName: 'Banter',

      age: 21

    }]

  };

});