Giter VIP home page Giter VIP logo

ionic-es6-awesome-app's Introduction

Ionic ES6 awesome app

An Ionic app built with ES6 and Hexagonal Architecture.

Setup

We will use the ionic-framework docker image for all the npm, bower and ionic stuff, so first of all pull the docker image:

docker pull agileek/ionic-framework

Next we will create the following aliases in order to use npm, bower and ionic commands:

alias ionicD="docker run -ti --net host --privileged -v /dev/bus/usb:/dev/bus/usb -v ~/.gradle:/root/.gradle -v \$PWD:/myApp:rw agileek/ionic-framework ionic"
alias bowerD="docker run -ti --net host --privileged -v /dev/bus/usb:/dev/bus/usb -v ~/.gradle:/root/.gradle -v \$PWD:/myApp:rw agileek/ionic-framework bower"
alias npmD="docker run -ti --net host --privileged -v /dev/bus/usb:/dev/bus/usb -v ~/.gradle:/root/.gradle -v \$PWD:/myApp:rw agileek/ionic-framework npm"

Finally we will run the following commands:

git clone [email protected]:armellini13/ionic-es6-awesome-app.git
cd ionic-es6-awesome-app
npmD install
bowerD install
npmD run compile
ionicD serve

You should then see on your browser the Ulabox Music application.

Development

ADVICE: If you are using WebStorm or PhpStorm change on settings, languages and frameworks JavaScript to ECMAScript6.

During development you will have to compile the ES6 code to ES5 code several times, for that reason there is the command:

npmD run compile:watch

compile:watch will look for any changes on the src/ directory and compile the code if there is any.

Testing

Tests are ran with karma, just use the command:

npmD t

Running on Android

To run the app on your Android device use the following commands:

ionicD platform add android
ionicD build android
ionicD run android

Remember to have your devide connected and on developer mode. If there are any issues check the FAQ on agileek/ionic-framework

App structure

The aim of this project is to show how you can build an Ionic application with ES6 and Hexagonal Architecture. The code is a simple Ionic app that searches for songs using the Spotify API. The code is uncomplete and it is the aim of the programmer that clones this repository to complete the code as he/she wants to understand the structure of the application.

All the code related to AngularJS is found in src/Awesome/Infrastructure/View/AngularJS. The file Main.js is the entry point of the app and sets up the whole application registering the controllers, services, states and configuration defined on the files AngularJS/Config/Config.js, AngularJS/Config/States.js, AngularJS/Services/Controllers.js and AngularJS/Services/Services.js.

How to create a new page

1- Go to src/Awesome/Infrastructure/View/AngularJS/Config/States.js and define a new state, for example:

{
    name: 'App.Foo',
    url: '/foo',
    views: {
      'menuContent': {
        templateUrl: 'templates/foo.html',
        controller: 'FooCtrl'
      }
    }
  }

NOTE: Notice that the url is defined not as 'Foo' but as 'App.Foo' and the view is defined inside 'menuContent'. The reason for this is because we are using Ionic's side menu. App is the main state, and the different states that we can access from the side menu are defined like this. For more information read here.

2- Create the controller in src/Awesome/Infrastructure/View/AngularJS/Controllers/Foo.js

class FooCtrl {
  constructor($scope) {
    
  }
}

FooCtrl.$inject = ['$scope'];

export default FooCtrl;

Remember to add into the $inject array all the services you want to inject to the controller.

3- Declare the controller inside src/Awesome/Infrastructure/View/AngularJS/Config/Services/Controllers.js

{
  name: 'FooCtrl',
  controller: FooCtrl
}

4- Create the template for the controller inside www/templates/foo.html

<ion-view view-title="Foo">
  <ion-content>
    Foo content
  </ion-content>
</ion-view>

NOTE: Remember to use the ion-view and ion-content directves so you content is not shown under the navigation bar.

How to create a service

1- Create the service

class Bar {
  constructor(httpService) {
    
  }
}

export default Bar;

2- Declare the service inside src/Awesome/Infrastructure/View/AngularJS/Config/Services/Services.js

{
  name: 'Bar',
  service: Bar
}

Remember to define the services you want to inject inside your service. This is done in the same file where you declare it:

Bar.$inject = ['httpService'];

Way to go for completing the App

1- Inside the search page create an input to introduce the song to search and listen to the keyUp event. Then search.html should have something like:

<input type="text" ng-model="song" ng-keyUp="search(song)">

and the SearchCtrl something like:

constructor($scope) {
  $scope.search = function(song) {
    // Search the song
  }
}

2- Complete the SearchSong service defined in src/Awesome/Application/Service/SearchSong.js in order to use the SpotifyMusicApi service and return an array of Song objects. Remember to declare the services as shown before.

3- Inject the service inside the SearchCtrl and call its search function when there is a keyUp event.

constructor($scope, SearchSong) {
  $scope.search = function(song) {
    var results;
    
    // Search the song
    results = SearchSong.search(song);
  }
}

...

SearchCtrl.$inject = ['$scope', 'SearchSong'];

4- Show the results on the template!

// SearchCtrl.js
constructor($scope) {
  $scope.search = function(song) {
    // Search the song
    $scope.results = SearchSong.search(song);
  }
}
<input type="text" ng-model="song" ng-keyUp="search(song)">
<ion-list>
    <ion-item ng-repeat="result in results">
    {{result.name()}}
    {{result.artist()}}
  </ion-item>
</ion-list>

ADVICE: Check out this link and try to make the output nice!

ionic-es6-awesome-app's People

Contributors

0xaguspunk avatar liopic avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.