mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Create shared services module for backend angularjs, rename modules
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
ordersApp = angular.module("bulk_order_management", ["bulk_product_update"])
|
||||
orderManagementModule = angular.module("ofn.bulk_order_management", ["ofn.shared_services"])
|
||||
|
||||
ordersApp.config [
|
||||
orderManagementModule.config [
|
||||
"$httpProvider"
|
||||
(provider) ->
|
||||
provider.defaults.headers.common["X-CSRF-Token"] = $("meta[name=csrf-token]").attr("content")
|
||||
]
|
||||
|
||||
ordersApp.controller "AdminBulkOrdersCtrl", [
|
||||
orderManagementModule.controller "AdminOrderMgmtCtrl", [
|
||||
"$scope", "$http", "dataFetcher"
|
||||
($scope, $http, dataFetcher) ->
|
||||
$scope.updateStatusMessage =
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
productsApp = angular.module("bulk_product_update", [])
|
||||
productEditModule = angular.module("ofn.bulk_product_edit", ["ofn.shared_services"])
|
||||
|
||||
productsApp.config [
|
||||
productEditModule.config [
|
||||
"$httpProvider"
|
||||
(provider) ->
|
||||
provider.defaults.headers.common["X-CSRF-Token"] = $("meta[name=csrf-token]").attr("content")
|
||||
]
|
||||
|
||||
|
||||
productsApp.directive "ofnDecimal", ->
|
||||
productEditModule.directive "ofnDecimal", ->
|
||||
require: "ngModel"
|
||||
link: (scope, element, attrs, ngModel) ->
|
||||
numRegExp = /^\d+(\.\d+)?$/
|
||||
@@ -20,7 +20,7 @@ productsApp.directive "ofnDecimal", ->
|
||||
viewValue
|
||||
|
||||
|
||||
productsApp.directive "ofnTrackProduct", ->
|
||||
productEditModule.directive "ofnTrackProduct", ->
|
||||
require: "ngModel"
|
||||
link: (scope, element, attrs, ngModel) ->
|
||||
property_name = attrs.ofnTrackProduct
|
||||
@@ -31,7 +31,7 @@ productsApp.directive "ofnTrackProduct", ->
|
||||
viewValue
|
||||
|
||||
|
||||
productsApp.directive "ofnTrackVariant", ->
|
||||
productEditModule.directive "ofnTrackVariant", ->
|
||||
require: "ngModel"
|
||||
link: (scope, element, attrs, ngModel) ->
|
||||
property_name = attrs.ofnTrackVariant
|
||||
@@ -45,7 +45,7 @@ productsApp.directive "ofnTrackVariant", ->
|
||||
viewValue
|
||||
|
||||
|
||||
productsApp.directive "ofnToggleVariants", ->
|
||||
productEditModule.directive "ofnToggleVariants", ->
|
||||
link: (scope, element, attrs) ->
|
||||
if scope.displayProperties[scope.product.id].showVariants
|
||||
element.removeClass "icon-chevron-right"
|
||||
@@ -66,7 +66,7 @@ productsApp.directive "ofnToggleVariants", ->
|
||||
|
||||
|
||||
|
||||
productsApp.directive "ofnToggleColumn", ->
|
||||
productEditModule.directive "ofnToggleColumn", ->
|
||||
link: (scope, element, attrs) ->
|
||||
element.addClass "unselected" unless scope.column.visible
|
||||
element.click "click", ->
|
||||
@@ -78,7 +78,7 @@ productsApp.directive "ofnToggleColumn", ->
|
||||
scope.column.visible = true
|
||||
element.removeClass "unselected"
|
||||
|
||||
productsApp.directive "datetimepicker", [
|
||||
productEditModule.directive "datetimepicker", [
|
||||
"$parse"
|
||||
($parse) ->
|
||||
return (
|
||||
@@ -96,7 +96,7 @@ productsApp.directive "datetimepicker", [
|
||||
]
|
||||
|
||||
|
||||
productsApp.controller "AdminBulkProductsCtrl", [
|
||||
productEditModule.controller "AdminProductEditCtrl", [
|
||||
"$scope", "$timeout", "$http", "dataFetcher"
|
||||
($scope, $timeout, $http, dataFetcher) ->
|
||||
$scope.updateStatusMessage =
|
||||
@@ -441,21 +441,7 @@ productsApp.controller "AdminBulkProductsCtrl", [
|
||||
Object.keys($scope.dirtyProducts).length
|
||||
]
|
||||
|
||||
|
||||
productsApp.factory "dataFetcher", [
|
||||
"$http", "$q"
|
||||
($http, $q) ->
|
||||
return (dataLocation) ->
|
||||
deferred = $q.defer()
|
||||
$http.get(dataLocation).success((data) ->
|
||||
deferred.resolve data
|
||||
).error ->
|
||||
deferred.reject()
|
||||
|
||||
deferred.promise
|
||||
]
|
||||
|
||||
productsApp.filter "rangeArray", ->
|
||||
productEditModule.filter "rangeArray", ->
|
||||
return (input,start,end) ->
|
||||
input.push(i) for i in [start..end]
|
||||
input
|
||||
|
||||
14
app/assets/javascripts/admin/shared_services.js.coffee
Normal file
14
app/assets/javascripts/admin/shared_services.js.coffee
Normal file
@@ -0,0 +1,14 @@
|
||||
sharedServicesModule = angular.module("ofn.shared_services", [])
|
||||
|
||||
sharedServicesModule.factory "dataFetcher", [
|
||||
"$http", "$q"
|
||||
($http, $q) ->
|
||||
return (dataLocation) ->
|
||||
deferred = $q.defer()
|
||||
$http.get(dataLocation).success((data) ->
|
||||
deferred.resolve data
|
||||
).error ->
|
||||
deferred.reject()
|
||||
|
||||
deferred.promise
|
||||
]
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
|
||||
|
||||
%div{ 'ng-app' => 'bulk_product_update', 'ng-controller' => 'AdminBulkProductsCtrl', 'ng-init' => "initialise('#{@spree_api_key}');loading=true;" }
|
||||
%div{ 'ng-app' => 'ofn.bulk_product_edit', 'ng-controller' => 'AdminProductEditCtrl', 'ng-init' => "initialise('#{@spree_api_key}');loading=true;" }
|
||||
%div{ 'ng-show' => '!spree_api_key_ok' }
|
||||
{{ api_error_msg }}
|
||||
%div.option_tab_titles{ :class => "sixteen columns alpha" }
|
||||
|
||||
@@ -9,6 +9,7 @@ module.exports = function(config) {
|
||||
'app/assets/javascripts/shared/angular.js',
|
||||
'app/assets/javascripts/shared/angular-*.js',
|
||||
|
||||
'app/assets/javascripts/admin/shared_services.js.coffee',
|
||||
'app/assets/javascripts/admin/order_cycle.js.erb.coffee',
|
||||
'app/assets/javascripts/admin/bulk_order_management.js.coffee',
|
||||
'app/assets/javascripts/admin/bulk_product_update.js.coffee',
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
describe "AdminBulkOrdersCtrl", ->
|
||||
ctrl = scope = timeout = httpBackend = null
|
||||
describe "AdminOrderMgmtCtrl", ->
|
||||
ctrl = scope = httpBackend = null
|
||||
|
||||
beforeEach ->
|
||||
module "bulk_order_management"
|
||||
module "ofn.bulk_order_management"
|
||||
beforeEach inject(($controller, $rootScope, $httpBackend) ->
|
||||
scope = $rootScope.$new()
|
||||
ctrl = $controller
|
||||
httpBackend = $httpBackend
|
||||
|
||||
ctrl "AdminBulkOrdersCtrl", {$scope: scope, $timeout: timeout}
|
||||
ctrl "AdminOrderMgmtCtrl", {$scope: scope}
|
||||
)
|
||||
|
||||
describe "loading data upon initialisation", ->
|
||||
|
||||
@@ -258,18 +258,18 @@ describe "Maintaining a live record of dirty products and properties", ->
|
||||
|
||||
|
||||
|
||||
describe "AdminBulkProductsCtrl", ->
|
||||
describe "AdminProductEditCtrl", ->
|
||||
ctrl = scope = timeout = httpBackend = null
|
||||
|
||||
beforeEach ->
|
||||
module "bulk_product_update"
|
||||
module "ofn.bulk_product_edit"
|
||||
beforeEach inject(($controller, $timeout, $rootScope, $httpBackend) ->
|
||||
scope = $rootScope.$new()
|
||||
ctrl = $controller
|
||||
timeout = $timeout
|
||||
httpBackend = $httpBackend
|
||||
|
||||
ctrl "AdminBulkProductsCtrl", {$scope: scope, $timeout: timeout}
|
||||
ctrl "AdminProductEditCtrl", {$scope: scope, $timeout: timeout}
|
||||
)
|
||||
|
||||
describe "loading data upon initialisation", ->
|
||||
|
||||
Reference in New Issue
Block a user