From 2006e45afd3dadcfae5c86c591fc9f837a33c9a3 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 13 Mar 2013 11:33:56 +0100 Subject: [PATCH] removed outdated angular info --- developer_manual/app/appframework/angular.rst | 8 +- developer_manual/app/general/angular.rst | 376 ------------------ developer_manual/app/intro/createapp.rst | 7 +- 3 files changed, 8 insertions(+), 383 deletions(-) diff --git a/developer_manual/app/appframework/angular.rst b/developer_manual/app/appframework/angular.rst index 8229a3674..8e6f607b2 100644 --- a/developer_manual/app/appframework/angular.rst +++ b/developer_manual/app/appframework/angular.rst @@ -1,4 +1,6 @@ -JavaScript -========== +AngularJS +========= -.. sectionauthor:: Bernhard Posselt \ No newline at end of file +.. sectionauthor:: Bernhard Posselt + +The App Framework comes with tools for integrating :doc:`../general/angular` into the app. \ No newline at end of file diff --git a/developer_manual/app/general/angular.rst b/developer_manual/app/general/angular.rst index 8a1a97185..a014d1bce 100644 --- a/developer_manual/app/general/angular.rst +++ b/developer_manual/app/general/angular.rst @@ -114,382 +114,6 @@ When porting the News app to AngularJS we found that the benefits outweighed the But all in all you should build an optimized prototype and compare it to a non angular app to make sure that the user experience is good. -Using AngularJS in your project -------------------------------- - -Since you'll have lots of files, a buildscript is recommended to merge the JavaScript into a single file. For that `CoffeeScript `_ and a `Cakefile `_ is recommended. - -You can install CoffeeScript via NPM (nodejs package manager):: - - sudo npm -g install coffee-script - -Place the Cakefile in your app directory. When executing:: - - cake watch - -the Cakefile will automatically watch the coffee folder for changes and compile the files when it finds a change. - -The following folderstructure is recommended:: - - coffee/ - coffee/directives/ - coffee/filters/ - coffee/controllers/ - coffee/services/ - -For a simple example, take a look at the `apptemplateadvanced `_ app. - -Create your app ---------------- - -.. note:: For the sake of syntax highlightning, this tutorial will use JavaScript instead of CoffeeScript - -Your app initialization will be in:: - - coffee/app.coffee - -and will look like this: - -.. code-block:: javascript - - angular.module('YourApp', []). - config(['$provide', function($provide){ - - // Use this for configuration values - var Config = { - // your config values here - }; - - // declare your routes here - Config.routes = { - saveNameRoute: 'apptemplate_advanced_ajax_setsystemvalue' - }; - - return $provide.value('Config', Config); - } - ]); - -.. note:: It is important that this file is at the beginning of the compiled JavaScript! The square brackets [] create a new app. If you only use **angular.module('YourApp')** it will retrieve the app instance. - -You will want to also add the run function to the same file to do some initial setup. The run function is run once angular is set up. That doesnt mean though that the document is ready - -.. code-block:: javascript - - angular.module('YourApp'). - run(['$rootScope', function($rootScope){ - - var init = function(){ - $rootScope.$broadcast('routesLoaded'); - }; - - // this registers a callback that is executed once the routes have - // finished loading. Before this you cant really do request - OC.Router.registerLoadedCallback(init); - } - ]); - - -The next move is to add the **ng-app="YourApp"** attribute to the root element of your application. Everything inside of it will be processed by Angular. - - -Controllers ------------ -Controllers are the mediators between your view and your data. Assign controllers to different parts of your page. **Don't nest controllers!** Every controller should have one specific area of your page. - -A controller could look like this: - -.. code-block:: javascript - - angular.module('YourApp'). - factory('ExampleController', ['$scope', 'Config', 'Request', - function($scope, Config, Request){ - - var Controller = function($scope, Config, Request){ - var self = this; - - this.$scope = $scope; - this.config = Config; - this.request = Request; - - // bind methods on the scope so that you can access them in the - // controllers child HTML - this.$scope.saveName = function(name){ - self.saveName(name); - }; - }; - - /** - * Makes an ajax query to save the name - */ - Controller.prototype.saveName = function(name){ - this.request.saveName(this.config.routes.saveNameRoute, name); - }; - - return new Controller($scope, Config, Request); - } - ]); - -To each controller a **$scope** object is passed. The scope is the glue between the view and the controller. - -.. note:: because controllers use the $scope object to connect to the view, you shouldn't pass in references of DOM elements. Use directives if you need to bind behaviour to DOM elements. - -Inside the square brackets (['$scope', 'Config', 'Request', function ...), you define the dependencies that need to be passed in to the object. This is the how Dependency Injection works in Angular. - -A controller is bound to an HTML element with the **ng-controller** attribute. Everything on that element or below it will be in the controller's scope: - -.. code-block:: html - -
    -
  • -
- - - -Models & Services ------------------ -Models hold your data. There isn't a specific implementation for models in Angular but it's useful to put the data into own objects. Inside these objects you can create hashmaps for quick access by ID or simply add new functionality or properties to the data. - -This is a little example how you could encapsulate data for a Button Model. Most of the functionality should go into a generic parent object though, once you use more than one model. - -.. code-block:: javascript - - angular.module('YourApp'). - factory('ButtonModel', function(){ - - var ButtonModel = function(){ - this.buttons = []; - this.buttonHashMap = {}; - }; - - ButtonModel.prototype.add = function(button){ - this.buttons.add(button); - this.buttonHashMap[button.id] = button; - }; - - ButtonModel.prototype.getById = function(buttonId){ - return this.buttonHashMap[buttonId]; - }; - - ButtonModel.prototype.getItems = function(){ - return this.buttons; - }; - - return new ButtonModel(); - } - ]); - - -A service can be seen as a single instance of an item. You can use it to share data between controllers for instance. A model is a service, but you could create an even simpler service which contains only an object: - -.. code-block:: javascript - - angular.module('YourApp'). - factory('ActiveFeed', function(){ - return { - id: 5 - }; - } - ]); - - -Filters -------- -Filters are used to transform objects or strings before you render them. They are basically just a function that receive an input and returns a result. - -Built-In filters contain functions like **orderBy** (orders array of objects by a specific attribute) or **uppercase** (turns string to uppercase). - -.. note:: Due to performance reasons you shouldn't use filters to return objects by a certain foreign key. Remember: everytime an element is updated, everything is sent through the filter again (O(n) algorithmic complexity) - -A simple filter would look like this: - -.. code-block:: javascript - - angular.module('YourApp'). - filter('biggerThanX', function(){ - - var biggerThanX = function(elements, x){ - result = []; - for(var i=0; i x){ - results.push(elem); - } - } - return result; - }; - - return biggerThanX; - } - ); - ]); - - -Filters are used like Unix Pipes in the Bash: - -.. code-block:: html - -
    -
  • {{ item.someNumber }}
  • -
- - -Directives ----------- -Directives are powerful yet complex for beginners. You can create your own XML elements or XML attributes, or simply map eventlisteners to HTML elements. - -Everytime you are in need to do something directly to a DOM element, you should write a directive for it. - -This is an example that uses a directive to bind jQuery draggable and dropable to a DOM element: - - -.. code-block:: javascript - - angular.module('YourApp').directive('draggable', function(){ - - return function(scope, elm, attr){ - - var details = { - revert: true, - stack: '> li', - zIndex: 1000, - axis: 'y', - }; - - $(elm).draggable(details); - }; - }); - - angular.module('YourApp').directive('droppable', function(){ - - return function(scope, elm, attr){ - - var details = { - greedy: true, - drop: function(event, ui){ - console.log('this was dropped on me'); - console.log(ui.draggable); - scope.$apply(attr.droppable); - } - }; - - $(elm).droppable(details); - - - }; - }); - -It can now be applied to any element by simply adding an attribute: - - -.. code-block:: html - -
  • nothing to see here
  • -
      - - -Since a directive is a new element outside of the current Angular Framework, we have to trigger a view update by using the **scope.$apply** function. - -This is only a `fraction of directive applications `_ though. - - -Requests --------- -For simple post or get requests, Angular offers the **$http** object. It's very helpful to encapsulate it into an own object though. You will want to use the object to implicitely send the CSRF token to the server. - -.. code-block:: javascript - - angular.module('YourApp'). - factory('Request', ['$http', '$rootScope', 'Config', function($http, $rootScope, Config){ - - var Request = function($http, $rootScope, Config){ - var self = this; - - this.$http = $http; - this.$rootScope = $rootScope; - this.config = Config; - - // if the routes are not yet initialized we dont want to lose - // requests. Save all requests and run them when the routes are - // ready - this.initialized = false; - this.shelvedRequests = []; - - this.$rootScope.$on('routesLoaded', function(){ - for(var i=0; i`_ diff --git a/developer_manual/app/intro/createapp.rst b/developer_manual/app/intro/createapp.rst index 20bbf414f..0afae1467 100644 --- a/developer_manual/app/intro/createapp.rst +++ b/developer_manual/app/intro/createapp.rst @@ -53,7 +53,7 @@ ownCloud has to know what your app is. This information is located inside the :f 6 -For more information on the content of :file:`appinfo/info.xml` and what can be set, see: :doc:`../app/info` +For more information on the content of :file:`appinfo/info.xml` see: :doc:`../app/info` Enable the app -------------- @@ -94,11 +94,10 @@ To simplify the decision see this comparison chart: | Templates | :php:class:`OC_Template`| :php:class:`OC_Template` | | | | and `Twig`_ | +-----------------+-------------------------+--------------------------------+ -| Security | manual checks | enforces XSS, CSRF and | -| | | Authentication checks by | +| Security | manual checks | enforces XSS (Twig only), CSRF | +| | | and Authentication checks by | | | | default | +-----------------+-------------------------+--------------------------------+ .. _Twig: http://twig.sensiolabs.org .. _TDD: http://en.wikipedia.org/wiki/Test-driven_development -.. _Dependency Injection: \ No newline at end of file