From 567cbee9bc695d0fd86effb41500a8b0d2b81c3c Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Mon, 28 Sep 2015 21:20:46 +0000 Subject: [PATCH] webstaff: add angular-location-update dependency This module adds a $location.update_path() routine to allow changing the URL without forcing a controller reload. This module is copyright (c) 2015 anglibs and released under the MIT license and is taken from https://github.com/anglibs/angular-location-update. Signed-off-by: Galen Charlton Signed-off-by: Kathy Lussier --- Open-ILS/src/templates/staff/base_js.tt2 | 1 + Open-ILS/web/js/ui/default/staff/Gruntfile.js | 1 + Open-ILS/web/js/ui/default/staff/bower.json | 3 +- .../angular-location-update/.bower.json | 31 +++++++++++ .../extern/angular-location-update/LICENSE | 22 ++++++++ .../extern/angular-location-update/README.md | 52 +++++++++++++++++++ .../angular-location-update.js | 22 ++++++++ .../angular-location-update.min.js | 1 + .../extern/angular-location-update/bower.json | 22 ++++++++ .../angular-location-update/package.json | 25 +++++++++ 10 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/web/js/ui/default/staff/extern/angular-location-update/.bower.json create mode 100644 Open-ILS/web/js/ui/default/staff/extern/angular-location-update/LICENSE create mode 100644 Open-ILS/web/js/ui/default/staff/extern/angular-location-update/README.md create mode 100644 Open-ILS/web/js/ui/default/staff/extern/angular-location-update/angular-location-update.js create mode 100644 Open-ILS/web/js/ui/default/staff/extern/angular-location-update/angular-location-update.min.js create mode 100644 Open-ILS/web/js/ui/default/staff/extern/angular-location-update/bower.json create mode 100644 Open-ILS/web/js/ui/default/staff/extern/angular-location-update/package.json diff --git a/Open-ILS/src/templates/staff/base_js.tt2 b/Open-ILS/src/templates/staff/base_js.tt2 index 97a2ce0615..4601e9c39b 100644 --- a/Open-ILS/src/templates/staff/base_js.tt2 +++ b/Open-ILS/src/templates/staff/base_js.tt2 @@ -8,6 +8,7 @@ + diff --git a/Open-ILS/web/js/ui/default/staff/Gruntfile.js b/Open-ILS/web/js/ui/default/staff/Gruntfile.js index 8dcd3c1715..087f0ff829 100644 --- a/Open-ILS/web/js/ui/default/staff/Gruntfile.js +++ b/Open-ILS/web/js/ui/default/staff/Gruntfile.js @@ -22,6 +22,7 @@ module.exports = function(grunt) { 'bower_components/angular-bootstrap/ui-bootstrap.min.js', 'bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js', 'bower_components/angular-hotkeys/build/hotkeys.min.js', + 'bower_components/angular-location-update/angular-location-update.min.js', 'bower_components/jquery/dist/jquery.min.js', ] }] diff --git a/Open-ILS/web/js/ui/default/staff/bower.json b/Open-ILS/web/js/ui/default/staff/bower.json index dc441267a9..d31ec5c6e5 100644 --- a/Open-ILS/web/js/ui/default/staff/bower.json +++ b/Open-ILS/web/js/ui/default/staff/bower.json @@ -26,6 +26,7 @@ "angular-bootstrap": "~0.11.0" }, "dependencies": { - "angular-hotkeys": "chieffancypants/angular-hotkeys#~1.2.0" + "angular-hotkeys": "chieffancypants/angular-hotkeys#~1.2.0", + "angular-location-update": "./extern/angular-location-update/" } } diff --git a/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/.bower.json b/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/.bower.json new file mode 100644 index 0000000000..c31aaa7fe6 --- /dev/null +++ b/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/.bower.json @@ -0,0 +1,31 @@ +{ + "name": "angular-location-update", + "homepage": "https://github.com/anglibs/angular-location-update", + "authors": [ + "garmoshka-mo " + ], + "main": "angular-location-update.js", + "description": "Updates location path without reloading of controller", + "ignore": [ + "**/.*", + "*.yml", + "*.xml", + "node_modules", + "bower_components", + "test", + "tests" + ], + "dependencies": { + "angular": "*" + }, + "_release": "103e945c53", + "_resolution": { + "type": "branch", + "branch": "master", + "commit": "103e945c535f9c0e3479c4faf77930404c823f21" + }, + "_source": "git://github.com/anglibs/angular-location-update.git", + "_target": "*", + "_originalSource": "angular-location-update", + "_direct": true +} \ No newline at end of file diff --git a/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/LICENSE b/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/LICENSE new file mode 100644 index 0000000000..037a52f8ae --- /dev/null +++ b/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 anglibs + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/README.md b/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/README.md new file mode 100644 index 0000000000..1996b3ab42 --- /dev/null +++ b/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/README.md @@ -0,0 +1,52 @@ +# angular-location-update + +Updates location path without reloading of controller + +## Install + +1 `bower install angular-location-update --save` or [download](http://anglibs.github.io/angular-location-update/angular-location-update.min.js) or include hosted from github.io +```` + +```` + +2 Add module to your app: +```` + angular.module('your_app', ['ngLocationUpdate']); +```` + +## Usage + +```` +$location.update_path('/notes/1'); +$location.update_path('/notes/1/wysiwyg', true); +```` +Parameters: + 1. New path + 1. Keep old path in browser history (By default it will be **replaced** by new one) + +## When it's needed? + +For example you have route `/notes/new` which shows form for new note. + +In modern web app you may have no "Save" button - note created and saved to database once user made any change. +Then you would like to change route to `/notes/1` showing to user, that here is URL of his new document. +Also if he will refresh page or go back and forward using browser buttons - he will see what he expects. + +## FYI + +Did you know, that you can easily change your URLs + +from `http://mysite.com/#/notes/1` to `http://mysite.com/notes/1` + +For this: + 1. Config app: `angular.module('your_app').config(function($locationProvider) { $locationProvider.html5Mode(true); });` + 2. Add in your HTML `` + +More info: https://docs.angularjs.org/guide/$location + +## Credits + +Solution invented by guys in these threads: + 1. https://github.com/angular/angular.js/issues/1699 + 1. https://github.com/angular-ui/ui-router/issues/427 + 1. http://stackoverflow.com/questions/14974271/can-you-change-a-path-without-reloading-the-controller-in-angularjs diff --git a/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/angular-location-update.js b/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/angular-location-update.js new file mode 100644 index 0000000000..454f3cc9a2 --- /dev/null +++ b/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/angular-location-update.js @@ -0,0 +1,22 @@ +!function(angular, undefined) { 'use strict'; + + angular.module('ngLocationUpdate', []) + .run(['$route', '$rootScope', '$location', function ($route, $rootScope, $location) { + // todo: would be proper to change this to decorators of $location and $route + $location.update_path = function (path, keep_previous_path_in_history) { + if ($location.path() == path) return; + + var routeToKeep = $route.current; + $rootScope.$on('$locationChangeSuccess', function () { + if (routeToKeep) { + $route.current = routeToKeep; + routeToKeep = null; + } + }); + + $location.path(path); + if (!keep_previous_path_in_history) $location.replace(); + }; + }]); + +}(window.angular); diff --git a/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/angular-location-update.min.js b/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/angular-location-update.min.js new file mode 100644 index 0000000000..1639d3f447 --- /dev/null +++ b/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/angular-location-update.min.js @@ -0,0 +1 @@ +!function(n){"use strict";n.module("ngLocationUpdate",[]).run(["$route","$rootScope","$location",function(n,t,o){o.update_path=function(c,u){if(o.path()!=c){var a=n.current;t.$on("$locationChangeSuccess",function(){a&&(n.current=a,a=null)}),o.path(c),u||o.replace()}}}])}(window.angular); \ No newline at end of file diff --git a/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/bower.json b/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/bower.json new file mode 100644 index 0000000000..5592a6deb8 --- /dev/null +++ b/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/bower.json @@ -0,0 +1,22 @@ +{ + "name": "angular-location-update", + "version": "0.0.2", + "homepage": "https://github.com/anglibs/angular-location-update", + "authors": [ + "garmoshka-mo " + ], + "main": "angular-location-update.js", + "description": "Updates location path without reloading of controller", + "ignore": [ + "**/.*", + "*.yml", + "*.xml", + "node_modules", + "bower_components", + "test", + "tests" + ], + "dependencies": { + "angular": "*" + } +} diff --git a/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/package.json b/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/package.json new file mode 100644 index 0000000000..2dbebf5f3e --- /dev/null +++ b/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/package.json @@ -0,0 +1,25 @@ +{ + "name": "angular-location-update", + "version": "0.0.2", + "main": "angular-location-update.js", + "description": "Updates location path without reloading of controller", + "homepage": "https://github.com/anglibs/angular-location-update", + "bugs": "https://github.com/anglibs/angular-location-update/issues", + "author": { + "name": "garmoshka-mo", + "email": "dan@dub.ink" + }, + "repository": { + "type": "git", + "url": "git@github.com:anglibs/angular-location-update.git" + }, + "licenses": [ + { + "type": "MIT" + } + ], + "dependencies": { + }, + "devDependencies": { + } +} -- 2.43.2