-
-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
437 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
app/assets/javascripts/admin/order_cycles/controllers/order_cycles_controller.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
angular.module("admin.orderCycles").controller "OrderCyclesCtrl", ($scope, $q, StatusMessage, RequestMonitor, OrderCycles, Enterprises) -> | ||
$scope.RequestMonitor = RequestMonitor | ||
$scope.saveAll = -> OrderCycles.saveChanges($scope.order_cycles_form) | ||
$scope.ordersCloseAtLimit = -31 # days | ||
|
||
compileDataFor = (orderCycles) -> | ||
for orderCycle in orderCycles | ||
OrderCycles.linkToEnterprises(orderCycle) | ||
orderCycle.producerNames = orderCycle.producers.map((producer) -> producer.name).join(", ") | ||
orderCycle.shopNames = orderCycle.shops.map((shop) -> shop.name).join(", ") | ||
|
||
# NOTE: this is using the Enterprises service from the admin.enterprises module | ||
RequestMonitor.load ($scope.enterprises = Enterprises.index(includeBlank: true, action: "visible", ams_prefix: "basic")).$promise | ||
RequestMonitor.load ($scope.orderCycles = OrderCycles.index(ams_prefix: "index", "q[orders_close_at_gt]": "#{daysFromToday($scope.ordersCloseAtLimit)}")).$promise | ||
RequestMonitor.load $q.all([$scope.enterprises.$promise, $scope.orderCycles.$promise]).then -> compileDataFor($scope.orderCycles) | ||
|
||
$scope.$watch 'order_cycles_form.$dirty', (newVal, oldVal) -> | ||
StatusMessage.display 'notice', "You have unsaved changes" if newVal | ||
|
||
$scope.showMore = (days) -> | ||
$scope.ordersCloseAtLimit -= days | ||
existingIDs = Object.keys(OrderCycles.orderCyclesByID) | ||
RequestMonitor.load (orderCycles = OrderCycles.index(ams_prefix: "index", "q[orders_close_at_gt]": "#{daysFromToday($scope.ordersCloseAtLimit)}", "q[id_not_in][]": existingIDs)).$promise | ||
orderCycles.$promise.then -> | ||
compileDataFor(orderCycles) | ||
$scope.orderCycles.push(orderCycle) for orderCycle in orderCycles | ||
|
||
daysFromToday = (days) -> | ||
now = new Date | ||
now.setHours(0) | ||
now.setMinutes(0) | ||
now.setSeconds(0) | ||
now.setDate( now.getDate() + days ) | ||
now |
37 changes: 21 additions & 16 deletions
37
app/assets/javascripts/admin/order_cycles/order_cycles.js.erb.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
require 'open_food_network/order_cycle_permissions' | ||
|
||
class Api::Admin::IndexOrderCycleSerializer < ActiveModel::Serializer | ||
include OrderCyclesHelper | ||
|
||
attributes :id, :name, :orders_open_at, :orders_close_at, :status, :variant_count, :deletable | ||
attributes :coordinator, :producers, :shops, :viewing_as_coordinator | ||
attributes :edit_path, :clone_path, :delete_path | ||
|
||
def deletable | ||
can_delete?(object) | ||
end | ||
|
||
def variant_count | ||
object.variants.count | ||
end | ||
|
||
def status | ||
order_cycle_status_class object | ||
end | ||
|
||
def orders_open_at | ||
object.orders_open_at.to_s | ||
end | ||
|
||
def orders_close_at | ||
object.orders_close_at.to_s | ||
end | ||
|
||
def viewing_as_coordinator | ||
Enterprise.managed_by(options[:current_user]).include? object.coordinator | ||
end | ||
|
||
def coordinator | ||
Api::Admin::IdNameSerializer.new(object.coordinator).serializable_hash | ||
end | ||
|
||
def producers | ||
producers = object.suppliers.merge(visible_enterprises) | ||
ActiveModel::ArraySerializer.new(producers, {each_serializer: Api::Admin::IdNameSerializer}) | ||
end | ||
|
||
def shops | ||
shops = object.distributors.merge(visible_enterprises) | ||
ActiveModel::ArraySerializer.new(shops, {each_serializer: Api::Admin::IdNameSerializer}) | ||
end | ||
|
||
def edit_path | ||
edit_admin_order_cycle_path(object) | ||
end | ||
|
||
def clone_path | ||
clone_admin_order_cycle_path(object) | ||
end | ||
|
||
def delete_path | ||
admin_order_cycle_path(object) | ||
end | ||
|
||
private | ||
|
||
def visible_enterprises | ||
@visible_enterprises ||= OpenFoodNetwork::OrderCyclePermissions.new(options[:current_user], object).visible_enterprises | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
%colgroup | ||
%col | ||
%col{'style' => 'width: 20%;'} | ||
%col{'style' => 'width: 20%;'} | ||
- unless simple_index | ||
%col | ||
%col | ||
%col | ||
%col | ||
%col | ||
%col | ||
%col | ||
|
||
%thead | ||
%tr | ||
%th | ||
=t :name | ||
%th | ||
=t :open | ||
%th | ||
=t :close | ||
- unless simple_index | ||
%th | ||
=t :label_producers | ||
%th | ||
=t :coordinator | ||
%th | ||
=t :label_shops | ||
%th | ||
=t :products | ||
%th.actions | ||
%th.actions | ||
%th.actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
%div.sixteen.columns.alpha.omega#loading{ ng: { cloak: true, if: 'RequestMonitor.loading' } } | ||
%img.spinner{ src: "/assets/spinning-circles.svg" } | ||
%h1{ ng: { hide: 'orderCycles.length > 0' } } LOADING ORDER CYCLES | ||
%h1{ ng: { show: 'orderCycles.length > 0' } } LOADING... |
Oops, something went wrong.