diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-02-15 14:42:27 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-02-15 14:42:27 +0100 |
commit | 5b452bc093ebaca4dd95955bd47417d187968352 (patch) | |
tree | f8a3ddace9bcbff466793291121bb60fc2604d01 /js | |
parent | fde119e5fb41323a323380b9d62ab4ac5215325f (diff) | |
parent | f27619250b4124b53b952938b2efa7096ea345c2 (diff) |
Merge pull request #33 from owncloud/remove-ui-router
Remove ui-router
Diffstat (limited to 'js')
41 files changed, 3726 insertions, 10865 deletions
diff --git a/js/components/contactDetails/contactDetails_controller.js b/js/components/contactDetails/contactDetails_controller.js index 71833e21..d385d16d 100644 --- a/js/components/contactDetails/contactDetails_controller.js +++ b/js/components/contactDetails/contactDetails_controller.js @@ -1,6 +1,18 @@ -app.controller('contactdetailsCtrl', ['ContactService', function(ContactService) { +app.controller('contactdetailsCtrl', ['ContactService', '$routeParams', '$scope', function(ContactService, $routeParams, $scope) { var ctrl = this; + ctrl.uid = $routeParams.uid; + + $scope.$watch('ctrl.uid', function(newValue, oldValue) { + ctrl.changeContact(newValue); + }); + + ctrl.changeContact = function(uid) { + ContactService.getById(uid).then(function(contact) { + ctrl.contact = contact; + }); + }; + ctrl.updateContact = function() { ContactService.update(ctrl.contact); console.log('updating Contact'); diff --git a/js/components/contactDetails/contactDetails_directive.js b/js/components/contactDetails/contactDetails_directive.js index 93b89f3c..a547e1a9 100644 --- a/js/components/contactDetails/contactDetails_directive.js +++ b/js/components/contactDetails/contactDetails_directive.js @@ -4,9 +4,7 @@ app.directive('contactdetails', function() { scope: {}, controller: 'contactdetailsCtrl', controllerAs: 'ctrl', - bindToController: { - contact: '=data' - }, + bindToController: {}, templateUrl: OC.linkTo('contactsrework', 'templates/contactDetails.html') }; -});
\ No newline at end of file +}); @@ -8,38 +8,12 @@ * @copyright Hendrik Leppelsack 2015 */ -var app = angular.module('contactsApp', ['ui.router', 'uuid4', 'angular-cache']); +var app = angular.module('contactsApp', ['uuid4', 'angular-cache', 'ngRoute']); -app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider){ - $urlRouterProvider.otherwise('/'); +app.config(['$routeProvider', function($routeProvider){ - $stateProvider - .state('home', { - url: '/', - views: { - '': { - template: '<contactlist data-adrbook="addressBook"></contactlist>' - }, + $routeProvider.when("/:uid", { + template: '<contactdetails></contactdetails>' + }); - 'sidebar': { - template: '<div>none</div>' - } - } - }) - .state('home.detail', { - url: '/:uid', - views: { - 'sidebar@': { - template: '<contactdetails data="contact"></contactdetails>', - controller: function($scope, contact) { - $scope.contact = contact; - } - } - }, - resolve: { - contact: function(ContactService, $stateParams) { - return ContactService.getById($stateParams.uid); - } - } - }); }]); diff --git a/js/public/script.js b/js/public/script.js index 0a56ce20..6035cece 100644 --- a/js/public/script.js +++ b/js/public/script.js @@ -8,40 +8,14 @@ * @copyright Hendrik Leppelsack 2015 */ -var app = angular.module('contactsApp', ['ui.router', 'uuid4', 'angular-cache']); +var app = angular.module('contactsApp', ['uuid4', 'angular-cache', 'ngRoute']); -app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider){ - $urlRouterProvider.otherwise('/'); +app.config(['$routeProvider', function($routeProvider){ - $stateProvider - .state('home', { - url: '/', - views: { - '': { - template: '<contactlist data-adrbook="addressBook"></contactlist>' - }, + $routeProvider.when("/:uid", { + template: '<contactdetails></contactdetails>' + }); - 'sidebar': { - template: '<div>none</div>' - } - } - }) - .state('home.detail', { - url: '/:uid', - views: { - 'sidebar@': { - template: '<contactdetails data="contact"></contactdetails>', - controller: function($scope, contact) { - $scope.contact = contact; - } - } - }, - resolve: { - contact: function(ContactService, $stateParams) { - return ContactService.getById($stateParams.uid); - } - } - }); }]); app.controller('addressbookCtrl', function() { @@ -105,9 +79,21 @@ app.directive('contact', function() { templateUrl: OC.linkTo('contactsrework', 'templates/contact.html') }; }); -app.controller('contactdetailsCtrl', ['ContactService', function(ContactService) { +app.controller('contactdetailsCtrl', ['ContactService', '$routeParams', '$scope', function(ContactService, $routeParams, $scope) { var ctrl = this; + ctrl.uid = $routeParams.uid; + + $scope.$watch('ctrl.uid', function(newValue, oldValue) { + ctrl.changeContact(newValue); + }); + + ctrl.changeContact = function(uid) { + ContactService.getById(uid).then(function(contact) { + ctrl.contact = contact; + }); + }; + ctrl.updateContact = function() { ContactService.update(ctrl.contact); console.log('updating Contact'); @@ -125,12 +111,11 @@ app.directive('contactdetails', function() { scope: {}, controller: 'contactdetailsCtrl', controllerAs: 'ctrl', - bindToController: { - contact: '=data' - }, + bindToController: {}, templateUrl: OC.linkTo('contactsrework', 'templates/contactDetails.html') }; }); + app.controller('contactlistCtrl', ['$scope', 'ContactService', function($scope, ContactService) { var ctrl = this; @@ -378,6 +363,8 @@ app.factory('AddressBookService', ['DavClient', 'DavService', 'SettingsService', var contacts; app.service('ContactService', [ 'DavClient', 'AddressBookService', 'Contact', '$q', 'CacheFactory', 'uuid4', function(DavClient, AddressBookService, Contact, $q, CacheFactory, uuid4) { + var cacheFilled = false; + contacts = CacheFactory('contacts'); var observerCallbacks = []; @@ -405,18 +392,31 @@ app.service('ContactService', [ 'DavClient', 'AddressBookService', 'Contact', '$ }) ); }); - return $q.all(promises); + return $q.all(promises).then(function() { + cacheFilled = true; + }); }); }; this.getAll = function() { - return this.fillCache().then(function() { - return contacts.values(); - }); + if(cacheFilled === false) { + return this.fillCache().then(function() { + return contacts.values(); + }); + } else { + return $q.when(contacts.values()); + } + }; this.getById = function(uid) { - return contacts.get(uid); + if(cacheFilled === false) { + return this.fillCache().then(function() { + return contacts.get(uid); + }); + } else { + return $q.when(contacts.get(uid)); + } }; this.create = function(newContact, addressBook) { diff --git a/js/services/contact_service.js b/js/services/contact_service.js index f23dbabc..a5ebe86d 100644 --- a/js/services/contact_service.js +++ b/js/services/contact_service.js @@ -1,6 +1,8 @@ var contacts; app.service('ContactService', [ 'DavClient', 'AddressBookService', 'Contact', '$q', 'CacheFactory', 'uuid4', function(DavClient, AddressBookService, Contact, $q, CacheFactory, uuid4) { + var cacheFilled = false; + contacts = CacheFactory('contacts'); var observerCallbacks = []; @@ -28,18 +30,31 @@ app.service('ContactService', [ 'DavClient', 'AddressBookService', 'Contact', '$ }) ); }); - return $q.all(promises); + return $q.all(promises).then(function() { + cacheFilled = true; + }); }); }; this.getAll = function() { - return this.fillCache().then(function() { - return contacts.values(); - }); + if(cacheFilled === false) { + return this.fillCache().then(function() { + return contacts.values(); + }); + } else { + return $q.when(contacts.values()); + } + }; this.getById = function(uid) { - return contacts.get(uid); + if(cacheFilled === false) { + return this.fillCache().then(function() { + return contacts.get(uid); + }); + } else { + return $q.when(contacts.get(uid)); + } }; this.create = function(newContact, addressBook) { diff --git a/js/vendor/angular-cache/.bower.json b/js/vendor/angular-cache/.bower.json index ba16b368..fcbc98cf 100644 --- a/js/vendor/angular-cache/.bower.json +++ b/js/vendor/angular-cache/.bower.json @@ -41,6 +41,5 @@ }, "_source": "git://github.com/jmdobry/angular-cache.git", "_target": "~4.5.0", - "_originalSource": "angular-cache", - "_direct": true + "_originalSource": "angular-cache" }
\ No newline at end of file diff --git a/js/vendor/angular-route/.bower.json b/js/vendor/angular-route/.bower.json new file mode 100644 index 00000000..8d83f8ec --- /dev/null +++ b/js/vendor/angular-route/.bower.json @@ -0,0 +1,20 @@ +{ + "name": "angular-route", + "version": "1.5.0", + "license": "MIT", + "main": "./angular-route.js", + "ignore": [], + "dependencies": { + "angular": "1.5.0" + }, + "homepage": "https://github.com/angular/bower-angular-route", + "_release": "1.5.0", + "_resolution": { + "type": "version", + "tag": "v1.5.0", + "commit": "6f03a206107b3ae860ee7f7fd061db252c452903" + }, + "_source": "git://github.com/angular/bower-angular-route.git", + "_target": "^1.5.0", + "_originalSource": "angular-route" +}
\ No newline at end of file diff --git a/js/vendor/angular-ui-router/LICENSE b/js/vendor/angular-route/README.md index 6413b092..2cd4f909 100644 --- a/js/vendor/angular-ui-router/LICENSE +++ b/js/vendor/angular-route/README.md @@ -1,6 +1,53 @@ +# packaged angular-route + +This repo is for distribution on `npm` and `bower`. The source for this module is in the +[main AngularJS repo](https://github.com/angular/angular.js/tree/master/src/ngRoute). +Please file issues and pull requests against that repo. + +## Install + +You can install this package either with `npm` or with `bower`. + +### npm + +```shell +npm install angular-route +``` + +Then add `ngRoute` as a dependency for your app: + +```javascript +angular.module('myApp', [require('angular-route')]); +``` + +### bower + +```shell +bower install angular-route +``` + +Add a `<script>` to your `index.html`: + +```html +<script src="/bower_components/angular-route/angular-route.js"></script> +``` + +Then add `ngRoute` as a dependency for your app: + +```javascript +angular.module('myApp', ['ngRoute']); +``` + +## Documentation + +Documentation is available on the +[AngularJS docs site](http://docs.angularjs.org/api/ngRoute). + +## License + The MIT License -Copyright (c) 2013-2015 The AngularUI Team, Karsten Sperling +Copyright (c) 2010-2015 Google, Inc. http://angularjs.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/js/vendor/angular-route/angular-route.js b/js/vendor/angular-route/angular-route.js new file mode 100644 index 00000000..45ac238e --- /dev/null +++ b/js/vendor/angular-route/angular-route.js @@ -0,0 +1,1016 @@ +/** + * @license AngularJS v1.5.0 + * (c) 2010-2016 Google, Inc. http://angularjs.org + * License: MIT + */ +(function(window, angular, undefined) {'use strict'; + +/** + * @ngdoc module + * @name ngRoute + * @description + * + * # ngRoute + * + * The `ngRoute` module provides routing and deeplinking services and directives for angular apps. + * + * ## Example + * See {@link ngRoute.$route#example $route} for an example of configuring and using `ngRoute`. + * + * + * <div doc-module-components="ngRoute"></div> + */ + /* global -ngRouteModule */ +var ngRouteModule = angular.module('ngRoute', ['ng']). + provider('$route', $RouteProvider), + $routeMinErr = angular.$$minErr('ngRoute'); + +/** + * @ngdoc provider + * @name $routeProvider + * + * @description + * + * Used for configuring routes. + * + * ## Example + * See {@link ngRoute.$route#example $route} for an example of configuring and using `ngRoute`. + * + * ## Dependencies + * Requires the {@link ngRoute `ngRoute`} module to be installed. + */ +function $RouteProvider() { + function inherit(parent, extra) { + return angular.extend(Object.create(parent), extra); + } + + var routes = {}; + + /** + * @ngdoc method + * @name $routeProvider#when + * + * @param {string} path Route path (matched against `$location.path`). If `$location.path` + * contains redundant trailing slash or is missing one, the route will still match and the + * `$location.path` will be updated to add or drop the trailing slash to exactly match the + * route definition. + * + * * `path` can contain named groups starting with a colon: e.g. `:name`. All characters up + * to the next slash are matched and stored in `$routeParams` under the given `name` + * when the route matches. + * * `path` can contain named groups starting with a colon and ending with a star: + * e.g.`:name*`. All characters are eagerly stored in `$routeParams` under the given `name` + * when the route matches. + * * `path` can contain optional named groups with a question mark: e.g.`:name?`. + * + * For example, routes like `/color/:color/largecode/:largecode*\/edit` will match + * `/color/brown/largecode/code/with/slashes/edit` and extract: + * + * * `color: brown` + * * `largecode: code/with/slashes`. + * + * + * @param {Object} route Mapping information to be assigned to `$route.current` on route + * match. + * + * Object properties: + * + * - `controller` – `{(string|function()=}` – Controller fn that should be associated with + * newly created scope or the name of a {@link angular.Module#controller registered + * controller} if passed as a string. + * - `controllerAs` – `{string=}` – An identifier name for a reference to the controller. + * If present, the controller will be published to scope under the `controllerAs` name. + * - `template` – `{string=|function()=}` – html template as a string or a function that + * returns an html template as a string which should be used by {@link + * ngRoute.directive:ngView ngView} or {@link ng.directive:ngInclude ngInclude} directives. + * This property takes precedence over `templateUrl`. + * + * If `template` is a function, it will be called with the following parameters: + * + * - `{Array.<Object>}` - route parameters extracted from the current + * `$location.path()` by applying the current route + * + * - `templateUrl` – `{string=|function()=}` – path or function that returns a path to an html + * template that should be used by {@link ngRoute.directive:ngView ngView}. + * + * If `templateUrl` is a function, it will be called with the following parameters: + * + * - `{Array.<Object>}` - route parameters extracted from the current + * `$location.path()` by applying the current route + * + * - `resolve` - `{Object.<string, function>=}` - An optional map of dependencies which should + * be injected into the controller. If any of these dependencies are promises, the router + * will wait for them all to be resolved or one to be rejected before the controller is + * instantiated. + * If all the promises are resolved successfully, the values of the resolved promises are + * injected and {@link ngRoute.$route#$routeChangeSuccess $routeChangeSuccess} event is + * fired. If any of the promises are rejected the + * {@link ngRoute.$route#$routeChangeError $routeChangeError} event is fired. + * For easier access to the resolved dependencies from the template, the `resolve` map will + * be available on the scope of the route, under `$resolve` (by default) or a custom name + * specified by the `resolveAs` property (see below). This can be particularly useful, when + * working with {@link angular.Module#component components} as route templates.<br /> + * <div class="alert alert-warning"> + * **Note:** If your scope already contains a property with this name, it will be hidden + * or overwritten. Make sure, you specify an appropriate name for this property, that + * does not collide with other properties on the scope. + * </div> + * The map object is: + * + * - `key` – `{string}`: a name of a dependency to be injected into the controller. + * - `factory` - `{string|function}`: If `string` then it is an alias for a service. + * Otherwise if function, then it is {@link auto.$injector#invoke injected} + * and the return value is treated as the dependency. If the result is a promise, it is + * resolved before its value is injected into the controller. Be aware that + * `ngRoute.$routeParams` will still refer to the previous route within these resolve + * functions. Use `$route.current.params` to access the new route parameters, instead. + * + * - `resolveAs` - `{string=}` - The name under which the `resolve` map will be available on + * the scope of the route. If omitted, defaults to `$resolve`. + * + * - `redirectTo` – `{(string|function())=}` – value to update + * {@link ng.$location $location} path with and trigger route redirection. + * + * If `redirectTo` is a function, it will be called with the following parameters: + * + * - `{Object.<string>}` - route parameters extracted from the current + * `$location.path()` by applying the current route templateUrl. + * - `{string}` - current `$location.path()` + * - `{Object}` - current `$location.search()` + * + * The custom `redirectTo` function is expected to return a string which will be used + * to update `$location.path()` and `$location.search()`. + * + * - `[reloadOnSearch=true]` - `{boolean=}` - reload route when only `$location.search()` + * or `$location.hash()` changes. + * + * If the option is set to `false` and url in the browser changes, then + * `$routeUpdate` event is broadcasted on the root scope. + * + * - `[caseInsensitiveMatch=false]` - `{boolean=}` - match routes without being case sensitive + * + * If the option is set to `true`, then the particular route can be matched without being + * case sensitive + * + * @returns {Object} self + * + * @description + * Adds a new route definition to the `$route` service. + */ + this.when = function(path, route) { + //copy original route object to preserve params inherited from proto chain + var routeCopy = angular.copy(route); + if (angular.isUndefined(routeCopy.reloadOnSearch)) { + routeCopy.reloadOnSearch = true; + } + if (angular.isUndefined(routeCopy.caseInsensitiveMatch)) { + routeCopy.caseInsensitiveMatch = this.caseInsensitiveMatch; + } + routes[path] = angular.extend( + routeCopy, + path && pathRegExp(path, routeCopy) + ); + + // create redirection for trailing slashes + if (path) { + var redirectPath = (path[path.length - 1] == '/') + ? path.substr(0, path.length - 1) + : path + '/'; + + routes[redirectPath] = angular.extend( + {redirectTo: path}, + pathRegExp(redirect |