mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Compare commits
31 Commits
v4.4.32
...
v4.4.0-mas
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd889133cb | ||
|
|
4ac3dda398 | ||
|
|
9d5d269f1f | ||
|
|
f4405775f6 | ||
|
|
3a38361857 | ||
|
|
68b59ab7a6 | ||
|
|
a56541216e | ||
|
|
05d9646f3e | ||
|
|
b1de64bf3e | ||
|
|
e976cc6d95 | ||
|
|
9a89b22364 | ||
|
|
1b304e2aa4 | ||
|
|
48cdca59fd | ||
|
|
9095abfed2 | ||
|
|
aa9fd682d8 | ||
|
|
5b73ccb213 | ||
|
|
dda3cfa58d | ||
|
|
9da649a296 | ||
|
|
2e53b9a0c6 | ||
|
|
527e305e2f | ||
|
|
89b59f97ee | ||
|
|
26d3cffba3 | ||
|
|
86703bb545 | ||
|
|
8e99f496ff | ||
|
|
2f2506e698 | ||
|
|
7ef9c2f56a | ||
|
|
ee4402f751 | ||
|
|
79a2d1228d | ||
|
|
da3202460c | ||
|
|
75ccc5c72f | ||
|
|
aca72e6071 |
8
.env
8
.env
@@ -52,8 +52,6 @@ SMTP_PASSWORD="f00d"
|
||||
|
||||
# see="https://developers.google.com/maps/documentation/javascript/get-api-key
|
||||
# GOOGLE_MAPS_API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
# see https://developers.google.com/maps/documentation/javascript/localization#Region
|
||||
# GOOGLE_MAPS_REGION="XX"
|
||||
|
||||
# Stripe details for instance account
|
||||
# Find these under 'Developers' -> 'API keys' in your Stripe account dashboard.
|
||||
@@ -63,9 +61,3 @@ SMTP_PASSWORD="f00d"
|
||||
# STRIPE_INSTANCE_PUBLISHABLE_KEY="pk_test_xxxx" # This can be a test key or a live key
|
||||
# STRIPE_CLIENT_ID="ca_xxxx" # This can be a development ID or a production ID
|
||||
# STRIPE_ENDPOINT_SECRET="whsec_xxxx"
|
||||
|
||||
# New relic settings
|
||||
# see: https://one.eu.newrelic.com/admin-portal/, Administration > API keys to get the license key
|
||||
# NEW_RELIC_AGENT_ENABLED=true
|
||||
# NEW_RELIC_APP_NAME="Open Food Network"
|
||||
# NEW_RELIC_LICENSE_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
# ENV vars for the test environment
|
||||
# Override locally with `.env.test.local`
|
||||
|
||||
OFN_REDIS_JOBS_URL="redis://localhost:6379/2"
|
||||
|
||||
SECRET_TOKEN="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
STRIPE_INSTANCE_SECRET_KEY="bogus_key"
|
||||
STRIPE_SECRET_TEST_API_KEY="bogus_key"
|
||||
STRIPE_CUSTOMER="bogus_customer"
|
||||
STRIPE_ACCOUNT="bogus_account"
|
||||
STRIPE_CLIENT_ID="bogus_client_id"
|
||||
STRIPE_PUBLIC_TEST_API_KEY="bogus_stripe_publishable_key"
|
||||
|
||||
SITE_URL="test.host"
|
||||
|
||||
|
||||
31
.github/ISSUE_TEMPLATE/release.md
vendored
31
.github/ISSUE_TEMPLATE/release.md
vendored
@@ -7,26 +7,21 @@ assignees: ''
|
||||
|
||||
---
|
||||
|
||||
## 1. Preparation on Thursday
|
||||
## Preparation on Thursday
|
||||
|
||||
- [ ] Merge pull requests in the [Ready To Go] column
|
||||
- [ ] Include translations: `script/release/update_locales`
|
||||
- [ ] Increment version number: `git push upstream HEAD:refs/tags/vX.Y.Z`
|
||||
- Major: if server changes are required (eg. provision with ofn-install)
|
||||
- Minor: larger change that is irreversible (eg. migration deleting data)
|
||||
- Patch: all others. Shortcut: `script/release/tag`
|
||||
- [ ] Include translations: `tx pull --force`
|
||||
- [ ] [Draft new release]. Look at previous [releases] for inspiration.
|
||||
- Select new release tag
|
||||
- _Generate release notes_ and check to ensure all items are arranged in the right category.
|
||||
- [ ] Notify [#instance-managers] of user-facing :eyes:, API :warning: and experimental :construction: changes.
|
||||
- [ ] Notify [#instance-managers] of user-facing changes.
|
||||
|
||||
## 2. Testing
|
||||
## Testing
|
||||
|
||||
- [ ] [Find build] of the release commit and copy it below.
|
||||
- [ ] Move this issue to Test Ready.
|
||||
- [ ] Notify `@testers` in [#testing].
|
||||
- [ ] Test build: [Deploy to Staging] with release tag.
|
||||
- [ ] Test build: <!-- paste build link here, e.g. https://semaphore...builds/1234 -->
|
||||
|
||||
## 3. Finish on Tuesday
|
||||
## Finish on Tuesday
|
||||
|
||||
- [ ] Publish and notify [#global-community] (this is automatically posted with a plugin)
|
||||
- [ ] Deploy the new release to all managed instances.
|
||||
@@ -34,22 +29,20 @@ assignees: ''
|
||||
<pre>
|
||||
cd ofn-install
|
||||
git pull
|
||||
ansible-playbook --limit all_prod --extra-vars "git_version=vX.Y.Z" playbooks/deploy.yml
|
||||
ansible-playbook --limit all-prod --extra-vars "git_version=vx.y.z" playbooks/deploy.yml
|
||||
</pre>
|
||||
</details>
|
||||
- [ ] Notify [#instance-managers]:
|
||||
> @instance_managers The new release has been deployed.
|
||||
- [ ] [Create issue] for next release and confirm with next release manager in [#core-devs].
|
||||
- [ ] Nudge next release manager
|
||||
|
||||
The full process is described at https://github.com/openfoodfoundation/openfoodnetwork/wiki/Releasing.
|
||||
|
||||
[Ready To Go]: https://github.com/orgs/openfoodfoundation/projects/8?filterQuery=status%3A%22Ready+to+go+%F0%9F%9A%80%22
|
||||
[Ready To Go]: #zenhub
|
||||
[Transifex pull request]: https://github.com/openfoodfoundation/openfoodnetwork/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aopen+head%3Atransifex
|
||||
[Draft new release]: https://github.com/openfoodfoundation/openfoodnetwork/releases/new?tag=v&title=v+Code+Name&body=Congrats%0A%0ADescription%0A%0A
|
||||
[Draft new release]: https://github.com/openfoodfoundation/openfoodnetwork/releases/new?tag=v&title=v+Code+Name&body=Congrats%0A%0ADescription%0A%0A%23%23+User+facing+changes+:eyes:%0A%0A%0A%0A%23%23+Technical+changes+:wrench:%0A%0A
|
||||
[releases]: https://github.com/openfoodfoundation/openfoodnetwork/releases
|
||||
[#instance-managers]: https://app.slack.com/client/T02G54U79/CG7NJ966B
|
||||
[#testing]: https://openfoodnetwork.slack.com/app_redirect?channel=C02TZ6X00
|
||||
[Deploy to Staging]: https://github.com/openfoodfoundation/openfoodnetwork/actions/workflows/stage.yml
|
||||
[Find build]: https://semaphoreci.com/openfoodfoundation/openfoodnetwork-2/branches/master
|
||||
[#global-community]: https://app.slack.com/client/T02G54U79/C59ADD8F2
|
||||
[Create issue]: https://github.com/openfoodfoundation/openfoodnetwork/issues/new?assignees=&labels=&projects=&template=release.md&title=Release
|
||||
[#core-devs]: https://openfoodnetwork.slack.com/archives/GK2T38QPJ
|
||||
|
||||
7
.github/PULL_REQUEST_TEMPLATE.md
vendored
7
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -20,12 +20,7 @@
|
||||
|
||||
<!-- Please select one for your PR and delete the other. -->
|
||||
|
||||
Changelog Category (reviewers may add a label for the release notes):
|
||||
|
||||
- [ ] User facing changes
|
||||
- [ ] API changes (V0, V1, DFC or Webhook)
|
||||
- [ ] Technical changes only
|
||||
- [ ] Feature toggled
|
||||
Changelog Category: User facing changes | Technical changes
|
||||
|
||||
<!-- Choose a pull request title above which explains your change to a
|
||||
a user of the Open Food Network app. -->
|
||||
|
||||
37
.github/release.yml
vendored
37
.github/release.yml
vendored
@@ -1,37 +0,0 @@
|
||||
changelog:
|
||||
# Categorise according to what an instance manager needs to know
|
||||
categories:
|
||||
# Add the right label if anything appears in here.
|
||||
# Then re-generate the release notes.
|
||||
- title: "❓❓❓ Uncategorised ❓❓❓"
|
||||
labels:
|
||||
- '*'
|
||||
exclude:
|
||||
labels:
|
||||
- api changes
|
||||
- dependencies
|
||||
- feature toggled
|
||||
- technical changes only
|
||||
- user facing changes
|
||||
|
||||
# Posted in advance for #instance-managers
|
||||
- title: "User-facing changes 👀"
|
||||
labels:
|
||||
- user facing changes
|
||||
|
||||
- title: "API changes ⚠️"
|
||||
labels:
|
||||
- api changes
|
||||
|
||||
- title: "Experimental features for testing 🚧" # may be tested by instance managers
|
||||
labels:
|
||||
- feature toggled
|
||||
|
||||
# Instance managers ignore below
|
||||
- title: "Technical changes 🛠️"
|
||||
labels:
|
||||
- technical changes only
|
||||
|
||||
- title: "Dependencies 📦"
|
||||
labels:
|
||||
- dependencies
|
||||
28
.github/workflows/build.yml
vendored
28
.github/workflows/build.yml
vendored
@@ -17,7 +17,7 @@ permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
controllers:
|
||||
knapsack_rspec_controllers:
|
||||
runs-on: ubuntu-22.04
|
||||
services:
|
||||
postgres:
|
||||
@@ -85,7 +85,7 @@ jobs:
|
||||
git show --no-patch # the commit being tested (which is often a merge due to actions/checkout@v3)
|
||||
bundle exec rake knapsack_pro:rspec
|
||||
|
||||
models:
|
||||
knapsack_rspec_models:
|
||||
runs-on: ubuntu-22.04
|
||||
services:
|
||||
postgres:
|
||||
@@ -106,10 +106,10 @@ jobs:
|
||||
# [n] - where the n is a number of parallel jobs you want to run your tests on.
|
||||
# Use a higher number if you have slow tests to split them between more parallel jobs.
|
||||
# Remember to update the value of the `ci_node_index` below to (0..n-1).
|
||||
ci_node_total: [5]
|
||||
ci_node_total: [7]
|
||||
# Indexes for parallel jobs (starting from zero).
|
||||
# E.g. use [0, 1] for 2 parallel jobs, [0, 1, 2] for 3 parallel jobs, etc.
|
||||
ci_node_index: [0, 1, 2, 3, 4]
|
||||
ci_node_index: [0, 1, 2, 3, 4, 5, 6]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
@@ -154,7 +154,7 @@ jobs:
|
||||
run: |
|
||||
bundle exec rake knapsack_pro:rspec
|
||||
|
||||
system_admin:
|
||||
knapsack_rspec_system_admin:
|
||||
runs-on: ubuntu-22.04
|
||||
services:
|
||||
postgres:
|
||||
@@ -175,10 +175,10 @@ jobs:
|
||||
# [n] - where the n is a number of parallel jobs you want to run your tests on.
|
||||
# Use a higher number if you have slow tests to split them between more parallel jobs.
|
||||
# Remember to update the value of the `ci_node_index` below to (0..n-1).
|
||||
ci_node_total: [13]
|
||||
ci_node_total: [10]
|
||||
# Indexes for parallel jobs (starting from zero).
|
||||
# E.g. use [0, 1] for 2 parallel jobs, [0, 1, 2] for 3 parallel jobs, etc.
|
||||
ci_node_index: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
|
||||
ci_node_index: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
@@ -232,7 +232,7 @@ jobs:
|
||||
retention-days: 7
|
||||
if-no-files-found: ignore
|
||||
|
||||
system_consumer:
|
||||
knapsack_rspec_system_consumer:
|
||||
runs-on: ubuntu-22.04
|
||||
services:
|
||||
postgres:
|
||||
@@ -253,10 +253,10 @@ jobs:
|
||||
# [n] - where the n is a number of parallel jobs you want to run your tests on.
|
||||
# Use a higher number if you have slow tests to split them between more parallel jobs.
|
||||
# Remember to update the value of the `ci_node_index` below to (0..n-1).
|
||||
ci_node_total: [12]
|
||||
ci_node_total: [10]
|
||||
# Indexes for parallel jobs (starting from zero).
|
||||
# E.g. use [0, 1] for 2 parallel jobs, [0, 1, 2] for 3 parallel jobs, etc.
|
||||
ci_node_index: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
|
||||
ci_node_index: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
@@ -310,7 +310,7 @@ jobs:
|
||||
retention-days: 7
|
||||
if-no-files-found: ignore
|
||||
|
||||
engines:
|
||||
knapsack_rspec_engines:
|
||||
runs-on: ubuntu-22.04
|
||||
services:
|
||||
postgres:
|
||||
@@ -331,10 +331,10 @@ jobs:
|
||||
# [n] - where the n is a number of parallel jobs you want to run your tests on.
|
||||
# Use a higher number if you have slow tests to split them between more parallel jobs.
|
||||
# Remember to update the value of the `ci_node_index` below to (0..n-1).
|
||||
ci_node_total: [2]
|
||||
ci_node_total: [5]
|
||||
# Indexes for parallel jobs (starting from zero).
|
||||
# E.g. use [0, 1] for 2 parallel jobs, [0, 1, 2] for 3 parallel jobs, etc.
|
||||
ci_node_index: [0, 1]
|
||||
ci_node_index: [0, 1, 2, 3, 4]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
@@ -388,7 +388,7 @@ jobs:
|
||||
retention-days: 7
|
||||
if-no-files-found: ignore
|
||||
|
||||
test_the_rest:
|
||||
knapsack_rspec_test_the_rest:
|
||||
runs-on: ubuntu-22.04
|
||||
services:
|
||||
postgres:
|
||||
|
||||
2
.github/workflows/linters.yml
vendored
2
.github/workflows/linters.yml
vendored
@@ -18,7 +18,7 @@ jobs:
|
||||
uses: reviewdog/action-rubocop@v2
|
||||
with:
|
||||
rubocop_version: gemfile
|
||||
rubocop_extensions: rubocop-rails:gemfile rubocop-rspec:gemfile
|
||||
rubocop_extensions: rubocop-rails:gemfile
|
||||
reporter: github-pr-check
|
||||
level: error
|
||||
fail_on_error: true
|
||||
|
||||
2
.github/workflows/mapi.yml
vendored
2
.github/workflows/mapi.yml
vendored
@@ -28,7 +28,7 @@ jobs:
|
||||
with:
|
||||
mapi-token: ${{ secrets.MAPI_TOKEN }}
|
||||
api-url: http://localhost:3000
|
||||
api-spec: swagger/v1.yaml
|
||||
api-spec: swagger/v1/swagger.yaml
|
||||
target: openfoodfoundation/openfoodnetwork
|
||||
duration: 1min
|
||||
sarif-report: mapi.sarif
|
||||
|
||||
31
.github/workflows/stage.yml
vendored
31
.github/workflows/stage.yml
vendored
@@ -1,7 +1,7 @@
|
||||
name: "Deploy to Staging"
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
pull_request:
|
||||
types: [labeled]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
@@ -13,32 +13,24 @@ on:
|
||||
- staging.openfoodnetwork.org.uk
|
||||
- staging.openfoodnetwork.org.au
|
||||
- staging.coopcircuits.fr
|
||||
commit_ref:
|
||||
description: "Commit Reference"
|
||||
type: string
|
||||
required: false
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
deploy_pr:
|
||||
if: contains(fromJSON('["pr-staged-uk", "pr-staged-au", "pr-staged-fr"]'), github.event.label.name)
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: "Check user has write access"
|
||||
uses: "lannonbr/repo-permission-check-action@2.0.2"
|
||||
with:
|
||||
permission: "write"
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Configure deployment key
|
||||
if: success()
|
||||
run: |
|
||||
install -m 600 -D /dev/null ~/.ssh/id_rsa
|
||||
echo "${{ secrets.DEPLOYMENT_KEY }}" > ~/.ssh/id_rsa
|
||||
echo "${{ secrets.DEPLOYMENT_HOSTS }}" > ~/.ssh/known_hosts
|
||||
|
||||
- name: Deploy to Staging
|
||||
if: success()
|
||||
env:
|
||||
LABEL: ${{ github.event.label.name }}
|
||||
run: |
|
||||
ssh ofn-deploy@${{ github.event.label.description }} -o LogLevel=ERROR "pull-request-${{ github.event.pull_request.number }} ."
|
||||
|
||||
@@ -46,21 +38,12 @@ jobs:
|
||||
if: ${{ inputs.server }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: "Check user has write access"
|
||||
uses: "lannonbr/repo-permission-check-action@2.0.2"
|
||||
with:
|
||||
permission: "write"
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Configure deployment key
|
||||
if: success()
|
||||
run: |
|
||||
install -m 600 -D /dev/null ~/.ssh/id_rsa
|
||||
echo "${{ secrets.DEPLOYMENT_KEY }}" > ~/.ssh/id_rsa
|
||||
echo "${{ secrets.DEPLOYMENT_HOSTS }}" > ~/.ssh/known_hosts
|
||||
|
||||
- name: Deploy to Staging
|
||||
if: success()
|
||||
run: |
|
||||
ssh ofn-deploy@${{ inputs.server }} -o LogLevel=ERROR "$GITHUB_REF_NAME ${{ inputs.commit_ref || github.sha }}"
|
||||
ssh ofn-deploy@${{ inputs.server }} -o LogLevel=ERROR "$GITHUB_REF_NAME $GITHUB_SHA"
|
||||
|
||||
4
.husky/pre-commit
Executable file
4
.husky/pre-commit
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env sh
|
||||
. "$(dirname -- "$0")/_/husky.sh"
|
||||
|
||||
yarn pretty-quick --check --staged
|
||||
@@ -13,8 +13,7 @@ postcss.config.js
|
||||
|
||||
# SCSS
|
||||
# Enabled: most of admin
|
||||
/app/webpacker/css/admin/globals/mixins.scss
|
||||
/app/webpacker/css/admin/globals/variables.scss
|
||||
/app/webpacker/css/admin/globals/
|
||||
/app/webpacker/css/admin/shared/
|
||||
/app/webpacker/css/admin_v3/globals/variables.scss
|
||||
/app/webpacker/css/darkswarm/
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
#
|
||||
# The configuration is split into three files. Look into those files for more details.
|
||||
#
|
||||
require:
|
||||
- rubocop-rails
|
||||
- rubocop-rspec
|
||||
require: rubocop-rails
|
||||
inherit_from:
|
||||
|
||||
# The automatically generated todo list to ignore all current violations.
|
||||
@@ -15,10 +13,9 @@ inherit_from:
|
||||
# The relaxed style rules as a common starting point which we can refine.
|
||||
- .rubocop_relaxed_styleguide.yml
|
||||
|
||||
# Our Open Food Network style guides. If you want to see all violations,
|
||||
# Our Open Food Network style guide. If you want to see all violations,
|
||||
# then use only that configuration:
|
||||
#
|
||||
# bundle exec rubocop -c .rubocop_styleguide.yml
|
||||
#
|
||||
- .rubocop_styleguide.yml
|
||||
- .rubocop_rspec_styleguide.yml
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
# OFN styleguide for rubocop-rspec
|
||||
# Because there are so many, we will disable by default, and enable rules as needed.
|
||||
|
||||
Capybara:
|
||||
Enabled: false
|
||||
|
||||
RSpec:
|
||||
Enabled: false
|
||||
|
||||
FactoryBot:
|
||||
Enabled: false
|
||||
|
||||
RSpec/ExpectChange:
|
||||
Enabled: true
|
||||
EnforcedStyle: block
|
||||
|
||||
RSpec/MultipleExpectations:
|
||||
Max: 5 # Default 1
|
||||
|
||||
RSpec/MultipleMemoizedHelpers:
|
||||
Max: 10 # Default 5
|
||||
@@ -5,60 +5,26 @@ AllCops:
|
||||
NewCops: enable
|
||||
SuggestExtensions: false
|
||||
Exclude:
|
||||
- bin/**/*
|
||||
- db/**/*
|
||||
- config/**/*
|
||||
- script/**/*
|
||||
- vendor/**/*
|
||||
- node_modules/**/*
|
||||
- 'bin/**/*'
|
||||
- 'db/**/*'
|
||||
- 'config/**/*'
|
||||
- 'script/**/*'
|
||||
- 'vendor/**/*'
|
||||
- 'node_modules/**/*'
|
||||
# Excluding: inadequate Naming/FileName rule rejects GemFile name with camelcase
|
||||
- engines/web/Gemfile
|
||||
- 'engines/web/Gemfile'
|
||||
|
||||
Bundler/DuplicatedGem:
|
||||
Enabled: false
|
||||
|
||||
Layout/LineLength:
|
||||
Enabled: true
|
||||
Max: 100
|
||||
|
||||
Layout/MultilineMethodCallIndentation:
|
||||
Enabled: true
|
||||
EnforcedStyle: indented
|
||||
|
||||
# Don't think this is a big issue, mostly picking up RPSEC scope definitions
|
||||
# with lamdas and RSpec '.to change{}' blocks
|
||||
Lint/AmbiguousBlockAssociation:
|
||||
Enabled: false
|
||||
|
||||
Lint/MissingSuper:
|
||||
Exclude:
|
||||
- app/components/**/*
|
||||
|
||||
Lint/RaiseException:
|
||||
Enabled: true
|
||||
|
||||
Lint/StructNewOverride:
|
||||
Enabled: true
|
||||
|
||||
# Heaps of offences (> 100) in specs, mostly in situations where two or more
|
||||
# instances of a model are required, but only one is referenced. Difficult to
|
||||
# fix without making the spec look messy or rewriting it.
|
||||
# Should definitely fix at some point.
|
||||
Lint/UselessAssignment:
|
||||
Exclude:
|
||||
- spec/**/*
|
||||
## OFN SETTINGS
|
||||
#
|
||||
# Cop settings that have been agreed upon by the OFN community
|
||||
|
||||
Metrics:
|
||||
Enabled: true
|
||||
|
||||
Metrics/AbcSize:
|
||||
Max: 30 # default 17
|
||||
|
||||
Metrics/BlockLength:
|
||||
AllowedMethods: [
|
||||
"class_eval",
|
||||
"collection",
|
||||
"configure",
|
||||
"context",
|
||||
"delete",
|
||||
"describe",
|
||||
@@ -72,63 +38,30 @@ Metrics/BlockLength:
|
||||
"put",
|
||||
"resource",
|
||||
"resources",
|
||||
"response",
|
||||
"scenario",
|
||||
"shared_examples",
|
||||
"shared_examples_for",
|
||||
"xdescribe",
|
||||
]
|
||||
|
||||
Metrics/MethodLength:
|
||||
Enabled: true
|
||||
Max: 25 # default 10
|
||||
|
||||
Metrics/ParameterLists:
|
||||
CountKeywordArgs: false
|
||||
|
||||
Metrics/PerceivedComplexity:
|
||||
Enabled: true
|
||||
Max: 14 # default 8
|
||||
|
||||
Naming/PredicateName:
|
||||
Enabled: false
|
||||
|
||||
Naming/VariableNumber:
|
||||
AllowedIdentifiers:
|
||||
- street_address_1
|
||||
- street_address_2
|
||||
AllowedPatterns:
|
||||
- _v[\d]+
|
||||
|
||||
Rails/ApplicationRecord:
|
||||
Exclude:
|
||||
# Migrations should not contain application code:
|
||||
- db/migrate/*.rb
|
||||
|
||||
# Allow many-to-many associations without explicit model.
|
||||
# - It avoids the additional code of a model class.
|
||||
# - It simplifies the declaration of the association.
|
||||
# - Rails may know that there are no callbacks associated.
|
||||
Rails/HasAndBelongsToMany:
|
||||
Enabled: false
|
||||
|
||||
Rails/OutputSafety:
|
||||
Exclude:
|
||||
- spec/**/*
|
||||
- "db/migrate/*.rb"
|
||||
|
||||
Rails/SkipsModelValidations:
|
||||
AllowedMethods:
|
||||
- touch
|
||||
- touch_all
|
||||
- update_all
|
||||
- update_attribute
|
||||
- update_column
|
||||
- update_columns
|
||||
- "touch"
|
||||
- "touch_all"
|
||||
- "update_all"
|
||||
- "update_attribute"
|
||||
- "update_column"
|
||||
- "update_columns"
|
||||
|
||||
Style/Documentation:
|
||||
Enabled: false
|
||||
|
||||
Style/FormatStringToken:
|
||||
Style/StringLiterals:
|
||||
Enabled: false
|
||||
|
||||
Style/HashSyntax:
|
||||
@@ -138,5 +71,60 @@ Style/HashSyntax:
|
||||
Style/Send:
|
||||
Enabled: true
|
||||
|
||||
Style/StringLiterals:
|
||||
Layout/MultilineMethodCallIndentation:
|
||||
Enabled: true
|
||||
EnforcedStyle: indented
|
||||
|
||||
Layout/LineLength:
|
||||
Enabled: true
|
||||
Max: 100
|
||||
|
||||
Lint/RaiseException:
|
||||
Enabled: true
|
||||
|
||||
Lint/StructNewOverride:
|
||||
Enabled: true
|
||||
|
||||
Naming/VariableNumber:
|
||||
AllowedIdentifiers:
|
||||
- street_address_1
|
||||
- street_address_2
|
||||
|
||||
Bundler/DuplicatedGem:
|
||||
Enabled: false
|
||||
|
||||
## TEMPORARY/CONTESTED SETTINGS
|
||||
#
|
||||
# These are still to be decided upon, but recommended for inclusion by
|
||||
# oeoeaio after scrutinising offenses the codebase
|
||||
|
||||
# Don't think this is a big issue, mostly picking up RPSEC scope definitions
|
||||
# with lamdas and RSpec '.to change{}' blocks
|
||||
Lint/AmbiguousBlockAssociation:
|
||||
Enabled: false
|
||||
|
||||
# Heaps of offences (> 100) in specs, mostly in situations where two or more
|
||||
# instances of a model are required, but only one is referenced. Difficult to
|
||||
# fix without making the spec look messy or rewriting it.
|
||||
# Should definitely fix at some point.
|
||||
Lint/UselessAssignment:
|
||||
Exclude:
|
||||
- spec/**/*
|
||||
|
||||
Lint/MissingSuper:
|
||||
Exclude:
|
||||
- 'app/components/**/*'
|
||||
|
||||
Metrics/AbcSize:
|
||||
Max: 30 # default 17
|
||||
|
||||
Metrics/MethodLength:
|
||||
Enabled: true
|
||||
Max: 25 # default 10
|
||||
|
||||
Metrics/PerceivedComplexity:
|
||||
Enabled: true
|
||||
Max: 14 # default 8
|
||||
|
||||
Naming/PredicateName:
|
||||
Enabled: false
|
||||
|
||||
1000
.rubocop_todo.yml
1000
.rubocop_todo.yml
File diff suppressed because it is too large
Load Diff
@@ -1 +1 @@
|
||||
3.1.4
|
||||
3.0.3
|
||||
|
||||
33
Gemfile
33
Gemfile
@@ -1,11 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
source 'https://rubygems.org'
|
||||
ruby "3.0.3"
|
||||
git_source(:github) { |repo_name| "https://github.com/#{repo_name}.git" }
|
||||
|
||||
ruby File.read('.ruby-version').chomp
|
||||
|
||||
gem 'dotenv', require: 'dotenv/load' # Load ENV vars before other gems
|
||||
gem 'dotenv-rails', require: 'dotenv/rails-now' # Load ENV vars before other gems
|
||||
|
||||
gem 'rails'
|
||||
|
||||
@@ -17,7 +16,7 @@ gem "image_processing"
|
||||
gem 'activemerchant', '>= 1.78.0'
|
||||
gem 'angular-rails-templates', '>= 0.3.0'
|
||||
gem 'awesome_nested_set'
|
||||
gem 'ransack', '~> 4.1.0'
|
||||
gem 'ransack', '~> 2.6.0'
|
||||
gem 'responders'
|
||||
gem 'rexml'
|
||||
gem 'webpacker', '~> 5'
|
||||
@@ -32,7 +31,6 @@ gem "db2fog", github: "openfoodfoundation/db2fog", branch: "rails-7"
|
||||
gem "fog-aws", "~> 2.0" # db2fog does not support v3
|
||||
gem "mime-types" # required by fog
|
||||
|
||||
gem "validates_lengths_from_database"
|
||||
gem "valid_email2"
|
||||
|
||||
gem "catalog", path: "./engines/catalog"
|
||||
@@ -74,7 +72,7 @@ gem 'rswag-ui'
|
||||
|
||||
gem 'omniauth_openid_connect'
|
||||
gem 'omniauth-rails_csrf_protection'
|
||||
gem 'openid_connect'
|
||||
gem 'openid_connect', '~> 1.3'
|
||||
|
||||
gem 'angularjs-rails', '1.8.0'
|
||||
gem 'bugsnag'
|
||||
@@ -93,18 +91,19 @@ gem 'bootsnap', require: false
|
||||
gem 'geocoder'
|
||||
gem 'gmaps4rails'
|
||||
gem 'mimemagic', '> 0.3.5'
|
||||
gem 'paper_trail'
|
||||
gem 'paper_trail', '~> 12.1'
|
||||
gem 'rack-rewrite'
|
||||
gem 'rack-timeout'
|
||||
gem 'roadie-rails'
|
||||
|
||||
gem 'hiredis'
|
||||
gem 'puma'
|
||||
gem 'redis'
|
||||
gem 'redis', '>= 4.0', require: ['redis', 'redis/connection/hiredis']
|
||||
gem 'sidekiq'
|
||||
gem 'sidekiq-scheduler'
|
||||
|
||||
gem "cable_ready", "5.0.1"
|
||||
gem "stimulus_reflex", "3.5.0.rc3"
|
||||
gem "cable_ready", "5.0.0.rc2"
|
||||
gem "stimulus_reflex", "3.5.0.rc2"
|
||||
|
||||
gem 'combine_pdf'
|
||||
gem 'wicked_pdf'
|
||||
@@ -116,6 +115,8 @@ gem 'spreadsheet_architect' # write spreadsheets
|
||||
|
||||
gem 'whenever', require: false
|
||||
|
||||
gem 'test-unit', '~> 3.5'
|
||||
|
||||
gem 'coffee-rails', '~> 5.0.0'
|
||||
|
||||
gem 'angular_rails_csrf'
|
||||
@@ -133,18 +134,13 @@ gem 'flipper-ui'
|
||||
gem "view_component"
|
||||
gem 'view_component_reflex', '3.1.14.pre9'
|
||||
|
||||
# mini_portile2 is needed when installing with Vargant
|
||||
# https://openfoodnetwork.slack.com/archives/CEBMTRCNS/p1668439152992899
|
||||
gem 'mini_portile2', '~> 2.8'
|
||||
|
||||
gem "faraday"
|
||||
gem "private_address_check"
|
||||
|
||||
gem 'newrelic_rpm'
|
||||
|
||||
gem 'invisible_captcha'
|
||||
|
||||
group :production, :staging do
|
||||
gem 'ddtrace'
|
||||
gem 'sd_notify' # For better Systemd process management. Used by Puma.
|
||||
end
|
||||
|
||||
@@ -161,9 +157,8 @@ group :test, :development do
|
||||
gem 'letter_opener', '>= 1.4.1'
|
||||
gem 'rspec-rails', ">= 3.5.2"
|
||||
gem 'rspec-retry', require: false
|
||||
gem 'rswag'
|
||||
gem 'rswag-specs'
|
||||
gem 'shoulda-matchers'
|
||||
gem 'stimulus_reflex_testing'
|
||||
gem 'timecop'
|
||||
end
|
||||
|
||||
@@ -186,10 +181,8 @@ group :development do
|
||||
gem 'rails-erd'
|
||||
gem 'rubocop'
|
||||
gem 'rubocop-rails'
|
||||
gem 'rubocop-rspec'
|
||||
gem 'spring'
|
||||
gem 'spring-commands-rspec'
|
||||
gem 'spring-commands-rubocop'
|
||||
gem 'web-console'
|
||||
|
||||
gem 'rack-mini-profiler', '< 3.0.0'
|
||||
|
||||
590
Gemfile.lock
590
Gemfile.lock
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,5 @@
|
||||
[](https://github.com/openfoodfoundation/openfoodnetwork/actions/workflows/build.yml)
|
||||
[](https://codeclimate.com/github/openfoodfoundation/openfoodnetwork)
|
||||
|
||||
# Open Food Network
|
||||
|
||||
@@ -44,7 +45,7 @@ We use [KnapsackPro](https://knapsackpro.com/) for optimal parallelisation of ou
|
||||
|
||||
## Licence
|
||||
|
||||
Copyright (c) 2012 - 2024 Open Food Foundation, released under the AGPL licence.
|
||||
Copyright (c) 2012 - 2022 Open Food Foundation, released under the AGPL licence.
|
||||
|
||||
[survey]: https://docs.google.com/a/eaterprises.com.au/forms/d/1zxR5vSiU9CigJ9cEaC8-eJLgYid8CR8er7PPH9Mc-30/edit#
|
||||
[slack-invite]: https://join.slack.com/t/openfoodnetwork/shared_invite/zt-9sjkjdlu-r02kUMP1zbrTgUhZhYPF~A
|
||||
|
||||
1
Rakefile
1
Rakefile
@@ -7,3 +7,4 @@
|
||||
require_relative 'config/application'
|
||||
|
||||
Openfoodnetwork::Application.load_tasks
|
||||
|
||||
|
||||
@@ -68,6 +68,25 @@
|
||||
//= require textAngular.min.js
|
||||
//= require i18n/translations
|
||||
//= require darkswarm/i18n.translate.js
|
||||
//= require moment/min/moment.min.js
|
||||
//= require moment/locale/ar.js
|
||||
//= require moment/locale/ca.js
|
||||
//= require moment/locale/de.js
|
||||
//= require moment/locale/en-gb.js
|
||||
//= require moment/locale/es.js
|
||||
//= require moment/locale/fil.js
|
||||
//= require moment/locale/fr.js
|
||||
//= require moment/locale/it.js
|
||||
//= require moment/locale/nb.js
|
||||
//= require moment/locale/nl-be.js
|
||||
//= require moment/locale/pt-br.js
|
||||
//= require moment/locale/pt.js
|
||||
//= require moment/locale/ru.js
|
||||
//= require moment/locale/sv.js
|
||||
//= require moment/locale/tr.js
|
||||
//= require moment/locale/pl.js
|
||||
|
||||
//= require js-big-decimal/dist/web/js-big-decimal.min.js
|
||||
|
||||
// foundation
|
||||
//= require ../shared/mm-foundation-tpls-0.9.0-20180826174721.min.js
|
||||
|
||||
@@ -113,7 +113,7 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout
|
||||
(DirtyProducts.count() > 0 and confirm(t("unsaved_changes_confirmation"))) or (DirtyProducts.count() == 0)
|
||||
|
||||
editProductUrl = (product, variant) ->
|
||||
"/admin/products/" + product.id + ((if variant then "/variants/" + variant.id else "")) + "/edit"
|
||||
"/admin/products/" + product.permalink_live + ((if variant then "/variants/" + variant.id else "")) + "/edit"
|
||||
|
||||
$scope.editWarn = (product, variant) ->
|
||||
if confirm_unsaved_changes()
|
||||
@@ -135,7 +135,6 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout
|
||||
display_name: null
|
||||
on_hand: null
|
||||
price: null
|
||||
tax_category_id: null
|
||||
DisplayProperties.setShowVariants product.id, true
|
||||
|
||||
|
||||
@@ -163,7 +162,7 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout
|
||||
if confirm(t("are_you_sure"))
|
||||
$http(
|
||||
method: "DELETE"
|
||||
url: "/api/v0/products/" + product.id + "/variants/" + variant.id
|
||||
url: "/api/v0/products/" + product.permalink_live + "/variants/" + variant.id
|
||||
).then (response) ->
|
||||
$scope.removeVariant(product, variant)
|
||||
else
|
||||
@@ -248,6 +247,7 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout
|
||||
else
|
||||
product.variant_unit = product.variant_unit_scale = null
|
||||
|
||||
$scope.packVariant product, product.master if product.master
|
||||
|
||||
if product.variants
|
||||
for id, variant of product.variants
|
||||
@@ -298,6 +298,7 @@ filterSubmitProducts = (productsToFilter) ->
|
||||
if product.hasOwnProperty("id")
|
||||
filteredProduct = {id: product.id}
|
||||
filteredVariants = []
|
||||
filteredMaster = null
|
||||
hasUpdatableProperty = false
|
||||
|
||||
if product.hasOwnProperty("variants")
|
||||
@@ -307,6 +308,16 @@ filterSubmitProducts = (productsToFilter) ->
|
||||
variantHasUpdatableProperty = result.hasUpdatableProperty
|
||||
filteredVariants.push filteredVariant if variantHasUpdatableProperty
|
||||
|
||||
if product.master?.hasOwnProperty("unit_value")
|
||||
filteredMaster ?= { id: product.master.id }
|
||||
filteredMaster.unit_value = product.master.unit_value
|
||||
if product.master?.hasOwnProperty("unit_description")
|
||||
filteredMaster ?= { id: product.master.id }
|
||||
filteredMaster.unit_description = product.master.unit_description
|
||||
if product.master?.hasOwnProperty("display_as")
|
||||
filteredMaster ?= { id: product.master.id }
|
||||
filteredMaster.display_as = product.master.display_as
|
||||
|
||||
if product.hasOwnProperty("sku")
|
||||
filteredProduct.sku = product.sku
|
||||
hasUpdatableProperty = true
|
||||
@@ -335,9 +346,18 @@ filterSubmitProducts = (productsToFilter) ->
|
||||
if product.hasOwnProperty("category_id")
|
||||
filteredProduct.primary_taxon_id = product.category_id
|
||||
hasUpdatableProperty = true
|
||||
if product.hasOwnProperty("tax_category_id")
|
||||
filteredProduct.tax_category_id = product.tax_category_id
|
||||
hasUpdatableProperty = true
|
||||
if product.hasOwnProperty("inherits_properties")
|
||||
filteredProduct.inherits_properties = product.inherits_properties
|
||||
hasUpdatableProperty = true
|
||||
if product.hasOwnProperty("available_on")
|
||||
filteredProduct.available_on = product.available_on
|
||||
hasUpdatableProperty = true
|
||||
if filteredMaster?
|
||||
filteredProduct.master_attributes = filteredMaster
|
||||
hasUpdatableProperty = true
|
||||
if filteredVariants.length > 0 # Note that the name of the property changes to enable mass assignment of variants attributes with rails
|
||||
filteredProduct.variants_attributes = filteredVariants
|
||||
hasUpdatableProperty = true
|
||||
@@ -372,9 +392,6 @@ filterSubmitVariant = (variant) ->
|
||||
if variant.hasOwnProperty("display_name")
|
||||
filteredVariant.display_name = variant.display_name
|
||||
hasUpdatableProperty = true
|
||||
if variant.hasOwnProperty("tax_category_id")
|
||||
filteredVariant.tax_category_id = variant.tax_category_id
|
||||
hasUpdatableProperty = true
|
||||
if variant.hasOwnProperty("display_as")
|
||||
filteredVariant.display_as = variant.display_as
|
||||
hasUpdatableProperty = true
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
angular.module("admin.dropdown").directive "linksDropdown", ($window)->
|
||||
restrict: "C"
|
||||
scope:
|
||||
links: "="
|
||||
templateUrl: "admin/links_dropdown.html"
|
||||
@@ -11,8 +11,14 @@ angular.module("admin.indexUtils").directive "objForUpdate", (switchClass, pendi
|
||||
pendingChanges.remove(scope.object().id, scope.attr)
|
||||
scope.clear()
|
||||
else
|
||||
change =
|
||||
object: scope.object()
|
||||
type: scope.type
|
||||
attr: scope.attr
|
||||
value: if value? then value else ""
|
||||
scope: scope
|
||||
scope.pending()
|
||||
addPendingChange(scope.attr, value ? "")
|
||||
pendingChanges.add(scope.object().id, scope.attr, change)
|
||||
|
||||
scope.reset = (value) ->
|
||||
scope.savedValue = value
|
||||
@@ -28,33 +34,3 @@ angular.module("admin.indexUtils").directive "objForUpdate", (switchClass, pendi
|
||||
|
||||
scope.clear = ->
|
||||
switchClass( element, "", ["update-pending", "update-error", "update-success"], false )
|
||||
|
||||
# When a list of customer is filtered and we removed the "filtered value" from a customer, we
|
||||
# want to make sure the customer is updated. IE. filtering by tag, and removing said tag.
|
||||
# Deleting the "filtered value" from a customer will remove the customer entry, thus
|
||||
# removing "objForUpdate" directive from the active scope. That means $watch won't pick up
|
||||
# the attribute changed.
|
||||
# To ensure the customer is still updated, we check on the $destroy event to see if
|
||||
# the attribute has changed, if so we queue up the change.
|
||||
scope.$on '$destroy', (value) ->
|
||||
# No update
|
||||
return if scope.object()[scope.attr] is scope.savedValue
|
||||
|
||||
# For some reason the code attribute is removed from the object when cleared, so we add
|
||||
# an emptyvalue so it gets updated properly
|
||||
if scope.attr is "code" and scope.object()[scope.attr] is undefined
|
||||
scope.object()["code"] = ""
|
||||
|
||||
# Queuing up change
|
||||
addPendingChange(scope.attr, scope.object()[scope.attr])
|
||||
|
||||
# private
|
||||
|
||||
addPendingChange = (attr, value) ->
|
||||
change =
|
||||
object: scope.object()
|
||||
type: scope.type
|
||||
attr: attr
|
||||
value: value
|
||||
scope: scope
|
||||
pendingChanges.add(scope.object().id, attr, change)
|
||||
|
||||
@@ -24,9 +24,6 @@ angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $timeout,
|
||||
"order_bill_address_firstname",
|
||||
"order_bill_address_lastname",
|
||||
"order_bill_address_full_name",
|
||||
"order_bill_address_full_name_reversed",
|
||||
"order_bill_address_full_name_with_comma",
|
||||
"order_bill_address_full_name_with_comma_reversed",
|
||||
"variant_product_supplier_name",
|
||||
"order_email",
|
||||
"order_number",
|
||||
|
||||
@@ -42,10 +42,8 @@ angular.module('admin.payments').factory 'Payment', (AdminStripeElements, curren
|
||||
|
||||
submit: =>
|
||||
munged = @preprocess()
|
||||
PaymentResource.create({order_id: munged.order_id}, munged, (response, headers, status) ->
|
||||
rawHtml = Object.values(response).join('').replace('[object Object]true', '')
|
||||
document.body.innerHTML = rawHtml
|
||||
$window.history.pushState({}, '', "/admin/orders/" + munged.order_id + "/payments")
|
||||
PaymentResource.create({order_id: munged.order_id}, munged, (response, headers, status)=>
|
||||
$window.location.pathname = "/admin/orders/" + munged.order_id + "/payments"
|
||||
, (response) ->
|
||||
StatusMessage.display 'error', t("spree.admin.payments.source_forms.stripe.error_saving_payment")
|
||||
)
|
||||
|
||||
@@ -2,9 +2,6 @@ angular.module("admin.products").factory "VariantUnitManager", (availableUnits)
|
||||
class VariantUnitManager
|
||||
@units:
|
||||
'weight':
|
||||
0.001:
|
||||
name: 'mg'
|
||||
system: 'metric'
|
||||
1.0:
|
||||
name: 'g'
|
||||
system: 'metric'
|
||||
@@ -24,21 +21,12 @@ angular.module("admin.products").factory "VariantUnitManager", (availableUnits)
|
||||
0.001:
|
||||
name: 'mL'
|
||||
system: 'metric'
|
||||
0.01:
|
||||
name: 'cL'
|
||||
system: 'metric'
|
||||
0.1:
|
||||
name: 'dL'
|
||||
system: 'metric'
|
||||
1.0:
|
||||
name: 'L'
|
||||
system: 'metric'
|
||||
1000.0:
|
||||
name: 'kL'
|
||||
system: 'metric'
|
||||
4.54609:
|
||||
name: 'gal'
|
||||
system: 'metric'
|
||||
'items':
|
||||
1:
|
||||
name: 'items'
|
||||
@@ -72,13 +60,8 @@ angular.module("admin.products").factory "VariantUnitManager", (availableUnits)
|
||||
|
||||
@compatibleUnitScales: (scale, unitType) ->
|
||||
scaleSystem = @units[unitType][scale]['system']
|
||||
if availableUnits
|
||||
available = availableUnits.split(",")
|
||||
(parseFloat(scale) for scale, scaleInfo of @units[unitType] when scaleInfo['system'] == scaleSystem and available.includes(scaleInfo['name'])).sort (a, b) ->
|
||||
a - b
|
||||
else
|
||||
(parseFloat(scale) for scale, scaleInfo of @units[unitType] when scaleInfo['system'] == scaleSystem).sort (a, b) ->
|
||||
a - b
|
||||
(parseFloat(scale) for scale, scaleInfo of @units[unitType] when scaleInfo['system'] == scaleSystem).sort (a, b) ->
|
||||
a - b
|
||||
|
||||
@systemOfMeasurement: (scale, unitType) ->
|
||||
if @units[unitType][scale]
|
||||
|
||||
@@ -32,6 +32,9 @@ jQuery(function($) {
|
||||
});
|
||||
}
|
||||
|
||||
// Make flash messages dissapear
|
||||
setTimeout('$(".flash").fadeOut()', 5000);
|
||||
|
||||
// Highlight hovered table column
|
||||
$('table tbody tr td.actions a').hover(function(){
|
||||
var tr = $(this).closest('tr');
|
||||
|
||||
@@ -1,6 +1,22 @@
|
||||
// Shipments AJAX API
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
handle_ship_click = function(){
|
||||
var link = $(this);
|
||||
var shipment_number = link.data('shipment-number');
|
||||
var url = Spree.url( Spree.routes.orders_api + "/" + order_number + "/shipments/" + shipment_number + "/ship.json");
|
||||
$.ajax({
|
||||
type: "PUT",
|
||||
url: url
|
||||
}).done(function( msg ) {
|
||||
window.location.reload();
|
||||
}).error(function( msg ) {
|
||||
console.log(msg);
|
||||
});
|
||||
}
|
||||
$('.admin-order-edit-form a.ship').click(handle_ship_click);
|
||||
|
||||
//handle shipping method edit click
|
||||
$('a.edit-method').click(toggleMethodEdit);
|
||||
$('a.cancel-method').click(toggleMethodEdit);
|
||||
|
||||
@@ -50,11 +50,11 @@ $(document).ready(function() {
|
||||
if (quantity > maxQuantity) {
|
||||
quantity = maxQuantity;
|
||||
save.parents('tr').find('input.line_item_quantity').val(maxQuantity);
|
||||
ofnAlert(t("js.admin.orders.quantity_unavailable"));
|
||||
} else {
|
||||
adjustItems(shipment_number, variant_id, quantity, true);
|
||||
ofnAlert(t("js.admin.orders.quantity_adjusted"));
|
||||
}
|
||||
toggleItemEdit();
|
||||
|
||||
adjustItems(shipment_number, variant_id, quantity, true);
|
||||
return false;
|
||||
}
|
||||
$('a.save-item').click(handle_save_click);
|
||||
|
||||
@@ -11,5 +11,24 @@
|
||||
|
||||
//= require i18n/translations
|
||||
//= require darkswarm/i18n.translate.js
|
||||
//= require moment/min/moment.min.js
|
||||
//= require moment/locale/ar.js
|
||||
//= require moment/locale/ca.js
|
||||
//= require moment/locale/de.js
|
||||
//= require moment/locale/en-gb.js
|
||||
//= require moment/locale/es.js
|
||||
//= require moment/locale/fil.js
|
||||
//= require moment/locale/fr.js
|
||||
//= require moment/locale/it.js
|
||||
//= require moment/locale/nb.js
|
||||
//= require moment/locale/nl-be.js
|
||||
//= require moment/locale/pt-br.js
|
||||
//= require moment/locale/pt.js
|
||||
//= require moment/locale/ru.js
|
||||
//= require moment/locale/sv.js
|
||||
//= require moment/locale/tr.js
|
||||
//= require moment/locale/pl.js
|
||||
|
||||
window.angular = { module: function(noop){ return { value: function(){} } } }
|
||||
//= require js-big-decimal/dist/web/js-big-decimal.min.js
|
||||
|
||||
window.angular = { module: function(noop){ return { value: function(){} } } }
|
||||
@@ -29,6 +29,24 @@
|
||||
#
|
||||
#= require angular-flash.min.js
|
||||
#
|
||||
#= require moment/min/moment.min.js
|
||||
#= require moment/locale/ar.js
|
||||
#= require moment/locale/ca.js
|
||||
#= require moment/locale/de.js
|
||||
#= require moment/locale/en-gb.js
|
||||
#= require moment/locale/es.js
|
||||
#= require moment/locale/fil.js
|
||||
#= require moment/locale/fr.js
|
||||
#= require moment/locale/it.js
|
||||
#= require moment/locale/nb.js
|
||||
#= require moment/locale/nl-be.js
|
||||
#= require moment/locale/pt-br.js
|
||||
#= require moment/locale/pt.js
|
||||
#= require moment/locale/ru.js
|
||||
#= require moment/locale/sv.js
|
||||
#= require moment/locale/tr.js
|
||||
#= require moment/locale/pl.js
|
||||
#
|
||||
#= require modernizr
|
||||
#
|
||||
#= require foundation-sites/js/foundation.js
|
||||
|
||||
@@ -9,9 +9,10 @@ angular.module('Darkswarm').controller "RegistrationFormCtrl", ($scope, Registra
|
||||
$scope.create = (form) ->
|
||||
if ($scope.valid(form))
|
||||
$scope.disableButton()
|
||||
EnterpriseRegistrationService.create($scope.enableButton).then(() ->
|
||||
EnterpriseRegistrationService.create().then(() ->
|
||||
$scope.enableButton()
|
||||
)
|
||||
end
|
||||
|
||||
$scope.update = (nextStep, form) ->
|
||||
EnterpriseRegistrationService.update(nextStep) if $scope.valid(form)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
.ofn-drop-down
|
||||
%span
|
||||
%i.icon-check
|
||||
{{ 'admin.actions' | t }}
|
||||
%i{ 'ng-class' => "expanded && 'icon-caret-up' || !expanded && 'icon-caret-down'" }
|
||||
%div.menu{ 'ng-show' => "expanded" }
|
||||
%div{ 'ng-repeat' => "link in links" }
|
||||
%a.menu_item{ 'ng-if': "link.method", href: '{{link.url}}', target: "{{link.target || '_self'}}", data: { method: "{{ link.method }}", "ujs-navigate": "false", confirm: "{{link.confirm}}" } }
|
||||
%span
|
||||
%i{ ng: { class: "link.icon" } }
|
||||
%span {{ link.name }}
|
||||
%a.menu_item{ 'ng-if': "link.confirm && !link.method", href: '{{link.url}}', target: "{{link.target || '_self'}}", "data-confirm": "{{link.confirm}}" }
|
||||
%span
|
||||
%i{ ng: { class: "link.icon" } }
|
||||
%span {{ link.name }}
|
||||
%a.menu_item{ 'ng-if': "!link.confirm && !link.method", href: '{{link.url}}', target: "{{link.target || '_self'}}" }
|
||||
%span
|
||||
%i{ ng: { class: "link.icon" } }
|
||||
%span {{ link.name }}
|
||||
@@ -19,7 +19,7 @@
|
||||
.name {{ product.name }}
|
||||
.supplier {{ product.supplier_name }}
|
||||
|
||||
.exchange-product-variant{'ng-repeat' => 'variant in product.variants | visibleVariants:exchange:order_cycle.visible_variants_for_outgoing_exchanges | filter:variantSuppliedToOrderCycle as filteredVariants'}
|
||||
.exchange-product-variant{'ng-repeat' => 'variant in product.variants | visibleVariants:exchange:order_cycle.visible_variants_for_outgoing_exchanges | filter:variantSuppliedToOrderCycle'}
|
||||
%label
|
||||
%input{ type: 'checkbox', name: 'order_cycle_outgoing_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}',
|
||||
value: 1,
|
||||
@@ -27,8 +27,5 @@
|
||||
'id' => 'order_cycle_outgoing_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}',
|
||||
'ng-disabled' => '!order_cycle.editable_variants_for_outgoing_exchanges.hasOwnProperty(exchange.enterprise_id) || order_cycle.editable_variants_for_outgoing_exchanges[exchange.enterprise_id].indexOf(variant.id) < 0' }
|
||||
{{ variant.label }}
|
||||
|
||||
%em{ 'ng-if' => 'filteredVariants.length === 0' }
|
||||
{{ 'js.admin.panels.exchange_products.no_variants' | t }}
|
||||
|
||||
%div{ 'ng-include' => "'admin/panels/exchange_products_panel_footer.html'" }
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
.exchange-load-all-variants
|
||||
%div
|
||||
{{ 'js.admin.panels.exchange_products.variants_loaded' | t:{ num_of_variants_loaded: enterprises[exchange.enterprise_id].loaded_variants, total_number_of_variants: exchangeTotalVariants(exchange) } }}
|
||||
%em{ 'ng-if': 'enterprises[exchange.enterprise_id].loaded_variants > exchangeTotalVariants(exchange)' }
|
||||
{{ 'js.admin.panels.exchange_products.some_variants_hidden' | t }}
|
||||
%a{ 'ng-click' => 'loadAllExchangeProducts(exchange)', 'ng-show' => 'enterprises[exchange.enterprise_id].last_page_loaded < enterprises[exchange.enterprise_id].num_of_pages' }
|
||||
{{ 'js.admin.panels.exchange_products.load_all_variants' | t }}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
{{'hubs_delivery' | t}}
|
||||
.row
|
||||
.columns.small-12
|
||||
%a.cta-hub{"ng-href" => "{{::enterprise.path}}#/shop_panel", "ng-attr-target" => "{{ embedded_layout ? '_blank' : undefined}}",
|
||||
%a.cta-hub{"ng-href" => "{{::enterprise.path}}#/shop", "ng-attr-target" => "{{ embedded_layout ? '_blank' : undefined}}",
|
||||
"ng-class" => "{primary: enterprise.active, secondary: !enterprise.active}",
|
||||
"ng-click" => "$close()",
|
||||
"ofn-change-hub" => "enterprise"}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
.row
|
||||
.columns.small-12
|
||||
%a.cta-hub{"ng-repeat" => "hub in enterprise.hubs | filter:{id: '!'+enterprise.id} | orderBy:'-active'",
|
||||
"ng-href" => "{{::hub.path}}#/shop_panel", "ofn-empties-cart" => "hub",
|
||||
"ng-href" => "{{::hub.path}}#/shop", "ofn-empties-cart" => "hub",
|
||||
"ng-class" => "::{primary: hub.active, secondary: !hub.active}",
|
||||
"ng-click" => "$close()",
|
||||
"ofn-change-hub" => "hub"}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
%filter-selector{ 'selector-set' => "productPropertySelectors", objects: "[product] | propertiesWithValuesOf" }
|
||||
|
||||
.product-description{"ng-if" => "product.description_html"}
|
||||
%p.text-small{"ng-bind-html" => "::product.description_html", "data-controller" => "add-blank-to-link"}
|
||||
%p.text-small{"ng-bind-html" => "::product.description_html"}
|
||||
|
||||
.columns.small-12.medium-6.large-6.product-img
|
||||
%img{"ng-src" => "{{::product.largeImage}}", "ng-if" => "::product.largeImage"}
|
||||
|
||||
@@ -1 +1 @@
|
||||
.question-mark-icon{"ng-class" => "{open: tt_isOpen}", type: 'button'}
|
||||
%button.question-mark-icon{"ng-class" => "{open: tt_isOpen}", type: 'button'}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ScopedChannel < ApplicationCable::Channel
|
||||
class << self
|
||||
def for_id(id)
|
||||
"ScopedChannel:#{id}"
|
||||
end
|
||||
end
|
||||
|
||||
def subscribed
|
||||
stream_from "ScopedChannel:#{params[:id]}"
|
||||
end
|
||||
end
|
||||
@@ -1,29 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ConfirmModalComponent < ModalComponent
|
||||
# @param actions_alignment_class [String] possible classes: 'justify-space-around', 'justify-end'
|
||||
def initialize(
|
||||
id:,
|
||||
reflex: nil,
|
||||
controller: nil,
|
||||
message: nil,
|
||||
confirm_actions: nil,
|
||||
confirm_reflexes: nil,
|
||||
confirm_button_class: :primary,
|
||||
confirm_button_text: I18n.t('js.admin.modals.confirm'),
|
||||
cancel_button_text: I18n.t('js.admin.modals.cancel'),
|
||||
actions_alignment_class: 'justify-space-around'
|
||||
)
|
||||
super(id:, close_button: true)
|
||||
def initialize(id:, confirm_actions: nil, reflex: nil, controller: nil, message: nil, confirm_reflexes: nil)
|
||||
super(id: id, close_button: true)
|
||||
@confirm_actions = confirm_actions
|
||||
@reflex = reflex
|
||||
@confirm_reflexes = confirm_reflexes
|
||||
@controller = controller
|
||||
@message = message
|
||||
@confirm_button_class = confirm_button_class
|
||||
@confirm_button_text = confirm_button_text
|
||||
@cancel_button_text = cancel_button_text
|
||||
@actions_alignment_class = actions_alignment_class
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
%div{ id: @id, "data-controller": "modal #{@controller}", "data-action": "keyup@document->modal#closeIfEscapeKey", "data-#{@controller}-reflex-value": @reflex }
|
||||
.reveal-modal-bg.fade{ "data-modal-target": "background", "data-action": "click->modal#close" }
|
||||
.reveal-modal.fade.tiny.modal-component{ "data-modal-target": "modal" }
|
||||
.reveal-modal.fade.tiny.help-modal{ "data-modal-target": "modal" }
|
||||
= content
|
||||
|
||||
= render @message if @message
|
||||
|
||||
%div{ class: "modal-actions #{@actions_alignment_class}" }
|
||||
%input{ class: "button icon-plus #{close_button_class}", type: 'button', value: @cancel_button_text, "data-action": "click->modal#close" }
|
||||
%input{ id: 'modal-confirm-button', class: "button icon-plus #{@confirm_button_class}", type: 'button', value: @confirm_button_text, "data-action": @confirm_actions, "data-reflex": @confirm_reflexes }
|
||||
.modal-actions
|
||||
%input{ class: "button icon-plus #{close_button_class}", type: 'button', value: t('js.admin.modals.cancel'), "data-action": "click->modal#close" }
|
||||
%input{ class: "button icon-plus primary", type: 'button', value: t('js.admin.modals.confirm'), "data-action": @confirm_actions, "data-reflex": @confirm_reflexes }
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
.modal-actions {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
}
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
class HelpModalComponent < ModalComponent
|
||||
def initialize(id:, close_button: true)
|
||||
super(id:, close_button:)
|
||||
super(id: id, close_button: close_button)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
%div{ id: @id, "data-controller": "help-modal", "data-action": "keyup@document->help-modal#closeIfEscapeKey" }
|
||||
.reveal-modal-bg.fade{ "data-help-modal-target": "background", "data-action": "click->help-modal#close" }
|
||||
.reveal-modal.fade.small.modal-component{ "data-help-modal-target": "modal" }
|
||||
.reveal-modal.fade.small.help-modal{ "data-help-modal-target": "modal" }
|
||||
= content
|
||||
|
||||
- if close_button?
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
.help-modal {
|
||||
visibility: visible;
|
||||
position: fixed;
|
||||
top: 3em;
|
||||
}
|
||||
|
||||
/* prevent arrow on selected admin menu item appearing above modal */
|
||||
body.modal-open #admin-menu li.selected a::after {
|
||||
z-index: 0;
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ModalComponent < ViewComponent::Base
|
||||
def initialize(id:, close_button: true, instant: false, modal_class: :small)
|
||||
def initialize(id:, close_button: true)
|
||||
@id = id
|
||||
@close_button = close_button
|
||||
@instant = instant
|
||||
@modal_class = modal_class
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
%div{ id: @id, "data-controller": "modal", "data-action": "keyup@document->modal#closeIfEscapeKey", "data-modal-instant-value": @instant }
|
||||
.reveal-modal-bg.fade{ "data-modal-target": "background", "data-action": "click->modal#close" }
|
||||
.reveal-modal.fade.modal-component{ "data-modal-target": "modal", class: @modal_class }
|
||||
= content
|
||||
|
||||
- if close_button?
|
||||
.text-center
|
||||
%input{ class: "button icon-plus #{close_button_class}", type: 'button', value: t('js.admin.modals.close'), "data-action": "click->modal#close" }
|
||||
@@ -1,56 +0,0 @@
|
||||
// class name 'modal' is already taken by 'custom-alert' and 'custom-confirm'.
|
||||
.modal-component {
|
||||
visibility: visible;
|
||||
position: fixed;
|
||||
top: 3em;
|
||||
min-height: auto; // reset from reveal-modal
|
||||
|
||||
&.in {
|
||||
padding: 1.2rem;
|
||||
}
|
||||
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6,
|
||||
p {
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
|
||||
img {
|
||||
// Ensure image fits in container
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
}
|
||||
|
||||
/* prevent arrow on selected admin menu item appearing above modal */
|
||||
body.modal-open #admin-menu li.selected a::after {
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.modal-actions {
|
||||
display: flex;
|
||||
text-align: center; // Ensure text inside fullwidth buttons are centred on small screens
|
||||
|
||||
&.justify-space-around {
|
||||
justify-content: space-around;
|
||||
}
|
||||
|
||||
&.justify-end {
|
||||
justify-content: flex-end;
|
||||
input[type="button"] {
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 1024px) {
|
||||
flex-direction: column;
|
||||
justify-content: space-around;
|
||||
input[type="button"] {
|
||||
margin: 5px 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
15
app/components/pagination_component.rb
Normal file
15
app/components/pagination_component.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PaginationComponent < ViewComponentReflex::Component
|
||||
def initialize(pagy:, data:)
|
||||
super
|
||||
@count = pagy.count
|
||||
@page = pagy.page
|
||||
@per_page = pagy.items
|
||||
@pages = pagy.pages
|
||||
@next = pagy.next
|
||||
@prev = pagy.prev
|
||||
@data = data
|
||||
@series = pagy.series
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,16 @@
|
||||
= component_controller do
|
||||
%nav{"aria-label": "pagination"}
|
||||
.pagination
|
||||
.pagination-prev{data: @prev.nil? ? nil : @data, "data-page": @prev, class: "#{'inactive' if @prev.nil?}"}
|
||||
= I18n.t "components.pagination.previous"
|
||||
.pagination-pages
|
||||
- @series.each do |page|
|
||||
- if page == :gap
|
||||
.pagination-gap
|
||||
…
|
||||
- else
|
||||
.pagination-page{data: @data, "data-page": page, class: "#{'active' if page.to_i == @page}"}
|
||||
= page
|
||||
.pagination-next{data: @next.nil? ? nil : @data, "data-page": @next, class: "#{'inactive' if @next.nil?}"}
|
||||
= I18n.t "components.pagination.next"
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
nav {
|
||||
.pagination {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
font-size: 14px;
|
||||
|
||||
.pagination-prev, .pagination-next {
|
||||
cursor: pointer;
|
||||
|
||||
&:after, &:before {
|
||||
font-size: 2em;
|
||||
position: relative;
|
||||
top: 3px;
|
||||
}
|
||||
|
||||
&.inactive {
|
||||
cursor: default;
|
||||
color: $disabled-dark;
|
||||
}
|
||||
}
|
||||
|
||||
.pagination-prev {
|
||||
margin-left: 10px;
|
||||
|
||||
&:before {
|
||||
content: "‹";
|
||||
margin-left: 10px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
.pagination-next {
|
||||
margin-right: 10px;
|
||||
|
||||
&:after {
|
||||
content: "›";
|
||||
margin-left: 10px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.pagination-pages {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
|
||||
.pagination-gap, .pagination-page {
|
||||
padding: 0 0.5rem;
|
||||
margin-left: 10px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.pagination-gap {
|
||||
color: $disabled-dark;
|
||||
}
|
||||
|
||||
.pagination-page {
|
||||
color: $color-4;
|
||||
cursor: pointer;
|
||||
&.active {
|
||||
border-top: 3px solid $spree-blue;
|
||||
color: $spree-blue;
|
||||
cursor: default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
59
app/components/product_component.rb
Normal file
59
app/components/product_component.rb
Normal file
@@ -0,0 +1,59 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ProductComponent < ViewComponentReflex::Component
|
||||
DATETIME_FORMAT = '%F %T'
|
||||
|
||||
def initialize(product:, columns:)
|
||||
super
|
||||
@product = product
|
||||
@image = @product.image if product.image.present?
|
||||
@columns = columns.map do |c|
|
||||
{
|
||||
id: c[:value],
|
||||
value: column_value(c[:value])
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
# This must be define when using ProductComponent.with_collection()
|
||||
def collection_key
|
||||
@product.id
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
|
||||
def column_value(column)
|
||||
case column
|
||||
when 'name'
|
||||
@product.name
|
||||
when 'price'
|
||||
@product.price
|
||||
when 'unit'
|
||||
"#{@product.variants.first.unit_value} #{@product.variant_unit}"
|
||||
when 'producer'
|
||||
@product.supplier.name
|
||||
when 'category'
|
||||
@product.taxons.map(&:name).join(', ')
|
||||
when 'sku'
|
||||
@product.sku
|
||||
when 'on_hand'
|
||||
@product.on_hand || 0
|
||||
when 'on_demand'
|
||||
@product.on_demand
|
||||
when 'tax_category'
|
||||
@product.tax_category.name
|
||||
when 'inherits_properties'
|
||||
@product.inherits_properties
|
||||
when 'available_on'
|
||||
format_date(@product.available_on)
|
||||
when 'import_date'
|
||||
format_date(@product.import_date)
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength
|
||||
|
||||
private
|
||||
|
||||
def format_date(date)
|
||||
date&.strftime(DATETIME_FORMAT) || ''
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
%tr
|
||||
- @columns.each do |column|
|
||||
%td.products_column{class: column[:id]}
|
||||
- if column[:id] == "name" && @image&.attachment.present?
|
||||
= image_tag @image.url(:mini)
|
||||
= column[:value]
|
||||
180
app/components/products_table_component.rb
Normal file
180
app/components/products_table_component.rb
Normal file
@@ -0,0 +1,180 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ProductsTableComponent < ViewComponentReflex::Component
|
||||
include Pagy::Backend
|
||||
|
||||
SORTABLE_COLUMNS = ['name', 'import_date'].freeze
|
||||
SELECTABLE_COLUMNS = [
|
||||
{ label: I18n.t("admin.products_page.columns_selector.price"), value: "price" },
|
||||
{ label: I18n.t("admin.products_page.columns_selector.unit"), value: "unit" },
|
||||
{ label: I18n.t("admin.products_page.columns_selector.producer"), value: "producer" },
|
||||
{ label: I18n.t("admin.products_page.columns_selector.category"), value: "category" },
|
||||
{ label: I18n.t("admin.products_page.columns_selector.sku"), value: "sku" },
|
||||
{ label: I18n.t("admin.products_page.columns_selector.on_hand"), value: "on_hand" },
|
||||
{ label: I18n.t("admin.products_page.columns_selector.on_demand"), value: "on_demand" },
|
||||
{ label: I18n.t("admin.products_page.columns_selector.tax_category"), value: "tax_category" },
|
||||
{
|
||||
label: I18n.t("admin.products_page.columns_selector.inherits_properties"),
|
||||
value: "inherits_properties"
|
||||
},
|
||||
{ label: I18n.t("admin.products_page.columns_selector.available_on"), value: "available_on" },
|
||||
{ label: I18n.t("admin.products_page.columns_selector.import_date"), value: "import_date" }
|
||||
].sort do |a, b|
|
||||
a[:label] <=> b[:label]
|
||||
end.freeze
|
||||
|
||||
PER_PAGE_VALUE = [10, 25, 50, 100].freeze
|
||||
PER_PAGE = PER_PAGE_VALUE.map { |value| { label: value, value: value } }
|
||||
NAME_COLUMN = {
|
||||
label: I18n.t("admin.products_page.columns.name"), value: "name", sortable: true
|
||||
}.freeze
|
||||
|
||||
def initialize(user:)
|
||||
super
|
||||
@user = user
|
||||
@selectable_columns = SELECTABLE_COLUMNS
|
||||
@columns_selected = ['unit', 'price', 'on_hand', 'category', 'import_date']
|
||||
@per_page = PER_PAGE
|
||||
@per_page_selected = [10]
|
||||
@categories = [{ label: "All", value: "all" }] +
|
||||
Spree::Taxon.order(:name)
|
||||
.map { |taxon| { label: taxon.name, value: taxon.id.to_s } }
|
||||
@categories_selected = ["all"]
|
||||
@producers = [{ label: "All", value: "all" }] +
|
||||
OpenFoodNetwork::Permissions.new(@user)
|
||||
.managed_product_enterprises.is_primary_producer.by_name
|
||||
.map { |producer| { label: producer.name, value: producer.id.to_s } }
|
||||
@producers_selected = ["all"]
|
||||
@page = 1
|
||||
@sort = { column: "name", direction: "asc" }
|
||||
@search_term = ""
|
||||
end
|
||||
|
||||
# any change on a "reflex_data_attributes" (defined in the template) will trigger a re render
|
||||
def before_render
|
||||
fetch_products
|
||||
refresh_columns
|
||||
end
|
||||
|
||||
# Element refers to the component the data is set on
|
||||
def search_term
|
||||
# Element is SearchInputComponent
|
||||
@search_term = element.dataset['value']
|
||||
end
|
||||
|
||||
def toggle_column
|
||||
# Element is SelectorComponent
|
||||
column = element.dataset['value']
|
||||
@columns_selected = if @columns_selected.include?(column)
|
||||
@columns_selected - [column]
|
||||
else
|
||||
@columns_selected + [column]
|
||||
end
|
||||
end
|
||||
|
||||
def click_sort
|
||||
# Element is TableHeaderComponent
|
||||
@sort = {
|
||||
column: element.dataset['sort-value'],
|
||||
direction: element.dataset['sort-direction'] == "asc" ? "desc" : "asc"
|
||||
}
|
||||
end
|
||||
|
||||
def toggle_per_page
|
||||
# Element is SelectorComponent
|
||||
selected = element.dataset['value'].to_i
|
||||
@per_page_selected = [selected] if PER_PAGE_VALUE.include?(selected)
|
||||
end
|
||||
|
||||
def toggle_category
|
||||
# Element is SelectorWithFilterComponent
|
||||
category_clicked = element.dataset['value']
|
||||
@categories_selected = toggle_selector_with_filter(category_clicked, @categories_selected)
|
||||
end
|
||||
|
||||
def toggle_producer
|
||||
# Element is SelectorWithFilterComponent
|
||||
producer_clicked = element.dataset['value']
|
||||
@producers_selected = toggle_selector_with_filter(producer_clicked, @producers_selected)
|
||||
end
|
||||
|
||||
def change_page
|
||||
# Element is PaginationComponent
|
||||
page = element.dataset['page'].to_i
|
||||
@page = page if page > 0
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def refresh_columns
|
||||
@columns = @columns_selected.map do |column|
|
||||
{
|
||||
label: I18n.t("admin.products_page.columns.#{column}"),
|
||||
value: column,
|
||||
sortable: SORTABLE_COLUMNS.include?(column)
|
||||
}
|
||||
end.sort! { |a, b| a[:label] <=> b[:label] }
|
||||
@columns.unshift(NAME_COLUMN)
|
||||
end
|
||||
|
||||
def toggle_selector_with_filter(clicked, selected)
|
||||
selected = if selected.include?(clicked)
|
||||
selected - [clicked]
|
||||
else
|
||||
selected + [clicked]
|
||||
end
|
||||
|
||||
if clicked == "all" || selected.empty?
|
||||
selected = ["all"]
|
||||
elsif selected.include?("all") && selected.length > 1
|
||||
selected -= ["all"]
|
||||
end
|
||||
selected
|
||||
end
|
||||
|
||||
def fetch_products
|
||||
product_query = OpenFoodNetwork::Permissions.new(@user).editable_products.merge(product_scope)
|
||||
@products = product_query.ransack(ransack_query).result
|
||||
@pagy, @products = pagy(@products, items: @per_page_selected.first, page: @page)
|
||||
end
|
||||
|
||||
def product_scope
|
||||
scope = if @user.has_spree_role?("admin") || @user.enterprises.present?
|
||||
Spree::Product
|
||||
else
|
||||
Spree::Product.active
|
||||
end
|
||||
|
||||
scope.includes(product_query_includes)
|
||||
end
|
||||
|
||||
def ransack_query
|
||||
query = { s: "#{@sort[:column]} #{@sort[:direction]}" }
|
||||
|
||||
query = if @producers_selected.include?("all")
|
||||
query.merge({ supplier_id_eq: "" })
|
||||
else
|
||||
query.merge({ supplier_id_in: @producers_selected })
|
||||
end
|
||||
|
||||
query = query.merge({ name_cont: @search_term }) if @search_term.present?
|
||||
|
||||
if @categories_selected.include?("all")
|
||||
query.merge({ primary_taxon_id_eq: "" })
|
||||
else
|
||||
query.merge({ primary_taxon_id_in: @categories_selected })
|
||||
end
|
||||
end
|
||||
|
||||
def product_query_includes
|
||||
[
|
||||
:image,
|
||||
variants: [
|
||||
:default_price,
|
||||
:stock_locations,
|
||||
:stock_items,
|
||||
:variant_overrides
|
||||
]
|
||||
]
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,21 @@
|
||||
= component_controller(class: "products-table") do
|
||||
.products-table-form
|
||||
.products-table-form_filter_results
|
||||
= render(SearchInputComponent.new(value: @search_term, data: reflex_data_attributes(:search_term)))
|
||||
.products-table-form_categories_selector
|
||||
= render(SelectorWithFilterComponent.new(title: t("admin.products_page.filters.categories.title"), selected: @categories_selected, items: @categories, data: reflex_data_attributes(:toggle_category), selected_items_i18n_key: "admin.products_page.filters.categories.selected_categories"))
|
||||
.products-table-form_producers_selector
|
||||
= render(SelectorWithFilterComponent.new(title: t("admin.products_page.filters.producers.title"), selected: @producers_selected, items: @producers, data: reflex_data_attributes(:toggle_producer), selected_items_i18n_key: "admin.products_page.filters.producers.selected_producers"))
|
||||
.products-table-form_per-page_selector
|
||||
= render(SelectorComponent.new(title: t('admin.products_page.filters.per_page', count: @per_page_selected[0]), selected: @per_page_selected, items: @per_page, data: reflex_data_attributes(:toggle_per_page)))
|
||||
.products-table-form_columns_selector
|
||||
= render(SelectorComponent.new(title: t("admin.products_page.filters.columns"), selected: @columns_selected, items: @selectable_columns, data: reflex_data_attributes(:toggle_column)))
|
||||
|
||||
.products-table_table
|
||||
%table
|
||||
= render(TableHeaderComponent.new(columns: @columns, sort: @sort, data: reflex_data_attributes(:click_sort)))
|
||||
%tbody
|
||||
= render(ProductComponent.with_collection(@products, columns: @columns))
|
||||
|
||||
.products-table-form_pagination
|
||||
= render(PaginationComponent.new(pagy: @pagy, data: reflex_data_attributes(:change_page)))
|
||||
@@ -0,0 +1,47 @@
|
||||
.products-table {
|
||||
.products-table-form {
|
||||
display: grid;
|
||||
grid-template-columns: repeat( auto-fit, minmax(250px, 1fr) );
|
||||
grid-gap: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.products-table_table {
|
||||
box-shadow: 0 10px 10px -1px rgb(0 0 0 / 10%);
|
||||
}
|
||||
|
||||
.products-table-form_pagination {
|
||||
position: relative;
|
||||
top: -15px;
|
||||
|
||||
nav, .pagination {
|
||||
margin-top: 0;
|
||||
padding-top: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.products-table.loading {
|
||||
.products-table-form_pagination, .products-table_table {
|
||||
position: relative;
|
||||
|
||||
&:before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
.products-table_table {
|
||||
&:before {
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
background-size: 50px 50px;
|
||||
background-image: url("../images/spinning-circles.svg");
|
||||
}
|
||||
}
|
||||
}
|
||||
9
app/components/search_input_component.rb
Normal file
9
app/components/search_input_component.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SearchInputComponent < ViewComponentReflex::Component
|
||||
def initialize(value: nil, data: {})
|
||||
super
|
||||
@value = value
|
||||
@data = data
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
= component_controller do
|
||||
%div.search-input
|
||||
%input{type: 'text', placeholder: t("components.search_input.placeholder"), id: 'search_query', data: {action: 'debounced:input->search-input#search'}, value: @value}
|
||||
.search-button{data: @data}
|
||||
%i.fa.fa-search
|
||||
@@ -0,0 +1,23 @@
|
||||
.search-input {
|
||||
border: 1px solid $disabled-light;
|
||||
height: 3em;
|
||||
display: flex;
|
||||
line-height: 3em;
|
||||
align-items: center;
|
||||
|
||||
input {
|
||||
border: none;
|
||||
height: 3em;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
padding-right: 5px;
|
||||
}
|
||||
|
||||
.search-button {
|
||||
padding-right: 10px;
|
||||
padding-left: 5px;
|
||||
cursor: pointer;
|
||||
color: $color-4;
|
||||
}
|
||||
|
||||
}
|
||||
17
app/components/selector_component.rb
Normal file
17
app/components/selector_component.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SelectorComponent < ViewComponentReflex::Component
|
||||
def initialize(title:, selected:, items:, data: {})
|
||||
super
|
||||
@title = title
|
||||
@items = items.map do |item|
|
||||
{
|
||||
label: item[:label],
|
||||
value: item[:value],
|
||||
selected: selected.include?(item[:value])
|
||||
}
|
||||
end
|
||||
@selected = selected
|
||||
@data = data
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
= component_controller do
|
||||
.selector.selector-close
|
||||
.selector-main{ data: { action: "click->selector#toggle" } }
|
||||
.selector-main-title
|
||||
= @title
|
||||
.selector-arrow
|
||||
.selector-wrapper
|
||||
.selector-items
|
||||
- @items.each do |item|
|
||||
.selector-item{ class: ("selected" if item[:selected]), data: @data, "data-value": item[:value] }
|
||||
= item[:label]
|
||||
86
app/components/selector_component/selector_component.scss
Normal file
86
app/components/selector_component/selector_component.scss
Normal file
@@ -0,0 +1,86 @@
|
||||
.selector {
|
||||
position: relative;
|
||||
|
||||
.selector-main {
|
||||
border: 1px solid $disabled-light;
|
||||
height: 3em;
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
|
||||
.selector-main-title {
|
||||
line-height: 3em;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
}
|
||||
|
||||
.selector-arrow {
|
||||
position: absolute;
|
||||
right: 0px;
|
||||
height: 3em;
|
||||
width: 1.5em;
|
||||
top: -1px;
|
||||
|
||||
&:after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
right: 5px;
|
||||
margin-top: -5px;
|
||||
width: 0;
|
||||
height: 0;
|
||||
border-left: 5px solid transparent;
|
||||
border-right: 5px solid transparent;
|
||||
border-top: 5px solid $disabled-light;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.selector-wrapper {
|
||||
position: absolute;
|
||||
left: 0px;
|
||||
right: 0px;
|
||||
z-index: 1;
|
||||
background-color: white;
|
||||
margin-top: -1px;
|
||||
border: 1px solid $disabled-light;
|
||||
|
||||
.selector-items {
|
||||
overflow-y: auto;
|
||||
min-height: 6em;
|
||||
|
||||
.selector-item {
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
border-bottom: 1px solid $disabled-light;
|
||||
position: relative;
|
||||
height: 3em;
|
||||
line-height: 3em;
|
||||
|
||||
&:hover {
|
||||
background-color: #eee;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
&.selected {
|
||||
&:after {
|
||||
content: "✓";
|
||||
display: inline-block;
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
&.selector-close {
|
||||
.selector-wrapper {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
app/components/selector_with_filter_component.rb
Normal file
11
app/components/selector_with_filter_component.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SelectorWithFilterComponent < SelectorComponent
|
||||
def initialize(title:, selected:, items:, data: {},
|
||||
selected_items_i18n_key: 'components.selector_with_filter.selected_items')
|
||||
super(title: title, selected: selected, items: items, data: data)
|
||||
@selected_items = items.select { |item| @selected.include?(item[:value]) }
|
||||
@selected_items_i18n_key = selected_items_i18n_key
|
||||
@items = items
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,22 @@
|
||||
= component_controller do
|
||||
.super-selector.selector.selector-close
|
||||
.selector-main{ data: { action: "click->selector-with-filter#toggle" } }
|
||||
.super-selector-label
|
||||
= @title
|
||||
.super-selector-selected-items
|
||||
- case @selected_items.length
|
||||
- when 1, 2
|
||||
- @selected_items.each do |item|
|
||||
.super-selector-selected-item
|
||||
= item[:label]
|
||||
- else
|
||||
.super-selector-selected-item
|
||||
= t(@selected_items_i18n_key, count: @selected_items.length)
|
||||
.selector-arrow
|
||||
.selector-wrapper
|
||||
.super-selector-search
|
||||
%input{type: "text", placeholder: t("components.selector_with_filter.search_placeholder"), data: { action: "debounced:input->selector-with-filter#filter" } }
|
||||
.selector-items
|
||||
- @items.each do |item|
|
||||
.selector-item{ class: ("selected" if item[:selected]), data: @data.merge({ "selector-with-filter-target": "items" }), "data-value": item[:value] }
|
||||
= item[:label]
|
||||
@@ -0,0 +1,51 @@
|
||||
|
||||
.super-selector {
|
||||
position: relative;
|
||||
|
||||
.selector-main {
|
||||
.super-selector-label {
|
||||
padding-left: 5px;
|
||||
padding-right: 5px;
|
||||
margin-left: 10px;
|
||||
position: absolute;
|
||||
top: -1em;
|
||||
background-color: white;
|
||||
}
|
||||
}
|
||||
|
||||
.super-selector-selected-items {
|
||||
margin-left: 5px;
|
||||
margin-right: 2em;
|
||||
margin-top: 7px;
|
||||
display: flex;
|
||||
|
||||
.super-selector-selected-item {
|
||||
border: 1px solid $pale-blue;
|
||||
background-color: $spree-light-blue;
|
||||
border-radius: 20px;
|
||||
height: 2em;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
display: inline-block;
|
||||
margin-right: 5px;
|
||||
padding-top: 2px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
}
|
||||
|
||||
.selector-wrapper {
|
||||
.super-selector-search {
|
||||
border-bottom: 1px solid $disabled-light;
|
||||
padding: 10px 5px;
|
||||
|
||||
input {
|
||||
border: 1px solid $disabled-light;
|
||||
box-sizing: border-box;
|
||||
border-radius: 4px;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
= render ConfirmModalComponent.new(id: dom_id(@order, :ship), confirm_reflexes: "click->Admin::OrdersReflex#ship", controller: "orders", reflex: "Admin::Orders#ship") do
|
||||
%div{class: "margin-bottom-30"}
|
||||
%p= t('spree.admin.orders.shipment.mark_as_shipped_message_html')
|
||||
%div{class: "margin-bottom-30"}
|
||||
= hidden_field_tag :id, @order.id
|
||||
= label_tag do
|
||||
= check_box_tag :send_shipment_email, "1", true
|
||||
= t('spree.admin.orders.shipment.mark_as_shipped_label_message')
|
||||
@@ -1,7 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ShipOrderComponent < ViewComponent::Base
|
||||
def initialize(order:)
|
||||
@order = order
|
||||
end
|
||||
end
|
||||
10
app/components/table_header_component.rb
Normal file
10
app/components/table_header_component.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TableHeaderComponent < ViewComponentReflex::Component
|
||||
def initialize(columns:, sort:, data: {})
|
||||
super
|
||||
@columns = columns
|
||||
@sort = sort
|
||||
@data = data
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
= component_controller do
|
||||
%thead.table-header
|
||||
%tr
|
||||
- @columns.each do |column|
|
||||
%th{class: (column[:sortable] ? "th-sortable " : "" ) + (@sort[:column] == column[:value] ? " th-sorted-#{@sort[:direction]}" : ""), data: (@data if column[:sortable] == true), "data-sort-value": column[:value], "data-sort-direction": @sort[:direction]}
|
||||
= column[:label]
|
||||
@@ -0,0 +1,23 @@
|
||||
thead.table-header {
|
||||
th {
|
||||
&.th-sortable {
|
||||
cursor: pointer;
|
||||
}
|
||||
&.th-sorted-asc, &.th-sorted-desc {
|
||||
&:after {
|
||||
display: inline-block;
|
||||
padding-left: 10px;
|
||||
}
|
||||
}
|
||||
&.th-sorted-asc {
|
||||
&:after {
|
||||
content: "⇧";
|
||||
}
|
||||
}
|
||||
&.th-sorted-desc {
|
||||
&:after {
|
||||
content: "⇩";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
.vertical-ellipsis-menu{ "data-controller": "vertical-ellipsis-menu--component" }
|
||||
%i.fa.fa-ellipsis-v{ "data-action": "click->vertical-ellipsis-menu--component#toggle" }
|
||||
.vertical-ellipsis-menu-content{ "data-vertical-ellipsis-menu--component-target": "content" }
|
||||
= content
|
||||
@@ -1,6 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module VerticalEllipsisMenu
|
||||
class Component < ViewComponent::Base
|
||||
end
|
||||
end
|
||||
@@ -1,59 +0,0 @@
|
||||
.vertical-ellipsis-menu {
|
||||
position: relative;
|
||||
|
||||
i.fa-ellipsis-v {
|
||||
cursor: pointer;
|
||||
display: block;
|
||||
text-align: center;
|
||||
border-radius: 3px;
|
||||
background-color: white;
|
||||
padding: 9px 14px;
|
||||
}
|
||||
|
||||
.vertical-ellipsis-menu-content {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
padding-top: 5px;
|
||||
padding-bottom: 5px;
|
||||
background-color: white;
|
||||
box-shadow: $box-shadow;
|
||||
border-radius: 3px;
|
||||
min-width: 80px;
|
||||
display: none;
|
||||
z-index: 100;
|
||||
|
||||
&.show {
|
||||
display: block;
|
||||
}
|
||||
|
||||
& > a {
|
||||
display: block;
|
||||
padding: 5px 10px;
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
border-left: 3px solid white;
|
||||
color: $near-black;
|
||||
text-decoration: none;
|
||||
border-bottom: none;
|
||||
|
||||
&:hover {
|
||||
background-color: $light-grey;
|
||||
border-left: 3px solid $spree-blue;
|
||||
}
|
||||
|
||||
&.delete {
|
||||
color: $red;
|
||||
|
||||
&:hover {
|
||||
border-left: 3px solid $red;
|
||||
background-color: $fair-pink;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
table.products td .vertical-ellipsis-menu {
|
||||
float: right;
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
import { Controller } from "stimulus";
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ["content"];
|
||||
|
||||
connect() {
|
||||
super.connect();
|
||||
window.addEventListener("click", this.#hideIfClickedOutside);
|
||||
}
|
||||
|
||||
toggle() {
|
||||
this.contentTarget.classList.toggle("show");
|
||||
}
|
||||
|
||||
#hideIfClickedOutside = (event) => {
|
||||
if (this.element.contains(event.target)) {
|
||||
return;
|
||||
}
|
||||
this.#hide();
|
||||
};
|
||||
|
||||
#hide() {
|
||||
this.contentTarget.classList.remove("show");
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ module Admin
|
||||
@line_items = order_permissions.
|
||||
editable_line_items.where(order_id: orders).
|
||||
includes(:variant).
|
||||
ransack(params[:q]).result.order(:id)
|
||||
ransack(params[:q]).result
|
||||
|
||||
@pagy, @line_items = pagy(@line_items) if pagination_required?
|
||||
|
||||
@@ -34,8 +34,7 @@ module Admin
|
||||
# and https://www.postgresql.org/docs/current/static/sql-select.html#SQL-FOR-UPDATE-SHARE
|
||||
order.with_lock do
|
||||
if order.contents.update_item(@line_item, line_item_params)
|
||||
# No Content, does not trigger ng resource auto-update
|
||||
render body: nil, status: :no_content
|
||||
render body: nil, status: :no_content # No Content, does not trigger ng resource auto-update
|
||||
else
|
||||
render json: { errors: @line_item.errors }, status: :precondition_failed
|
||||
end
|
||||
|
||||
@@ -11,7 +11,7 @@ module Admin
|
||||
respond_override update: { json: {
|
||||
success: lambda {
|
||||
tag_rule_mapping = TagRule.mapping_for(Enterprise.where(id: @customer.enterprise))
|
||||
render_as_json @customer, tag_rule_mapping:
|
||||
render_as_json @customer, tag_rule_mapping: tag_rule_mapping
|
||||
},
|
||||
failure: lambda {
|
||||
render json: { errors: @customer.errors.full_messages },
|
||||
@@ -25,7 +25,7 @@ module Admin
|
||||
format.json do
|
||||
render json: @collection,
|
||||
each_serializer: ::Api::Admin::CustomerWithBalanceSerializer,
|
||||
tag_rule_mapping:,
|
||||
tag_rule_mapping: tag_rule_mapping,
|
||||
customer_tags: customer_tags_by_id
|
||||
end
|
||||
end
|
||||
@@ -36,13 +36,11 @@ module Admin
|
||||
end
|
||||
|
||||
def create
|
||||
@customer = Customer.find_or_initialize_by(customer_params.slice(:email, :enterprise_id))
|
||||
|
||||
@customer = Customer.new(customer_params)
|
||||
if user_can_create_customer?
|
||||
@customer.created_manually = true
|
||||
if @customer.save
|
||||
tag_rule_mapping = TagRule.mapping_for(Enterprise.where(id: @customer.enterprise))
|
||||
render_as_json @customer, tag_rule_mapping:
|
||||
render_as_json @customer, tag_rule_mapping: tag_rule_mapping
|
||||
else
|
||||
render json: { errors: @customer.errors.full_messages }, status: :bad_request
|
||||
end
|
||||
@@ -85,7 +83,7 @@ module Admin
|
||||
def customers
|
||||
return @customers if @customers.present?
|
||||
|
||||
@customers = Customer.visible.managed_by(spree_current_user)
|
||||
@customers = Customer.managed_by(spree_current_user)
|
||||
return @customers if params[:enterprise_id].blank?
|
||||
|
||||
@customers = @customers.where(enterprise_id: params[:enterprise_id])
|
||||
|
||||
@@ -6,6 +6,8 @@ module Admin
|
||||
class EnterpriseFeesController < Admin::ResourceController
|
||||
before_action :load_enterprise_fee_set, only: :index
|
||||
before_action :load_data
|
||||
before_action :check_enterprise_fee_input, only: [:bulk_update]
|
||||
before_action :check_calculators_compatibility_with_taxes, only: [:bulk_update]
|
||||
|
||||
def index
|
||||
@include_calculators = params[:include_calculators].present?
|
||||
@@ -34,12 +36,10 @@ module Admin
|
||||
end
|
||||
|
||||
def bulk_update
|
||||
# Forms has strong parameters, so we don't need to validate them in controller
|
||||
@enterprise_fee_set = EnterpriseFeesBulkUpdate.new(params)
|
||||
@enterprise_fee_set = Sets::EnterpriseFeeSet.new(enterprise_fee_bulk_params)
|
||||
|
||||
if @enterprise_fee_set.save
|
||||
flash[:success] = I18n.t(:enterprise_fees_update_notice)
|
||||
redirect_to redirect_path
|
||||
redirect_to redirect_path, notice: I18n.t(:enterprise_fees_update_notice)
|
||||
else
|
||||
redirect_to redirect_path,
|
||||
flash: { error: @enterprise_fee_set.errors.full_messages.to_sentence }
|
||||
@@ -49,7 +49,7 @@ module Admin
|
||||
private
|
||||
|
||||
def load_enterprise_fee_set
|
||||
@enterprise_fee_set = Sets::EnterpriseFeeSet.new collection:
|
||||
@enterprise_fee_set = Sets::EnterpriseFeeSet.new collection: collection
|
||||
end
|
||||
|
||||
def load_data
|
||||
@@ -62,7 +62,9 @@ module Admin
|
||||
when :for_order_cycle
|
||||
order_cycle = OrderCycle.find_by(id: params[:order_cycle_id]) if params[:order_cycle_id]
|
||||
coordinator = Enterprise.find_by(id: params[:coordinator_id]) if params[:coordinator_id]
|
||||
order_cycle ||= OrderCycle.new(coordinator:) if coordinator.present?
|
||||
if order_cycle.nil? && coordinator.present?
|
||||
order_cycle = OrderCycle.new(coordinator: coordinator)
|
||||
end
|
||||
enterprises = OpenFoodNetwork::OrderCyclePermissions.new(spree_current_user,
|
||||
order_cycle).visible_enterprises
|
||||
EnterpriseFee.for_enterprises(enterprises).order('enterprise_id', 'fee_type', 'name')
|
||||
@@ -89,5 +91,47 @@ module Admin
|
||||
|
||||
main_app.admin_enterprise_fees_path
|
||||
end
|
||||
|
||||
def enterprise_fee_bulk_params
|
||||
params.require(:sets_enterprise_fee_set).permit(
|
||||
collection_attributes: [
|
||||
:id, :enterprise_id, :fee_type, :name, :tax_category_id,
|
||||
:inherits_tax_category, :calculator_type,
|
||||
{ calculator_attributes: PermittedAttributes::Calculator.attributes }
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
def check_enterprise_fee_input
|
||||
enterprise_fee_bulk_params['collection_attributes'].each do |_, fee_row|
|
||||
enterprise_fees = fee_row['calculator_attributes']&.slice(
|
||||
:preferred_flat_percent, :preferred_amount,
|
||||
:preferred_first_item, :preferred_additional_item,
|
||||
:preferred_minimal_amount, :preferred_normal_amount,
|
||||
:preferred_discount_amount, :preferred_per_unit
|
||||
)
|
||||
|
||||
next unless enterprise_fees
|
||||
|
||||
enterprise_fees.each do |_, enterprise_amount|
|
||||
unless enterprise_amount.nil? || Float(enterprise_amount, exception: false)
|
||||
flash[:error] = I18n.t(:calculator_preferred_value_error)
|
||||
return redirect_to redirect_path
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def check_calculators_compatibility_with_taxes
|
||||
enterprise_fee_bulk_params['collection_attributes'].each do |_, enterprise_fee|
|
||||
next unless enterprise_fee['inherits_tax_category'] == "true"
|
||||
next unless EnterpriseFee::PER_ORDER_CALCULATORS.include?(enterprise_fee['calculator_type'])
|
||||
|
||||
flash[:error] = I18n.t(
|
||||
'activerecord.errors.models.enterprise_fee.inherit_tax_requires_per_item_calculator'
|
||||
)
|
||||
return redirect_to redirect_path
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -39,7 +39,7 @@ module Admin
|
||||
# The ! version is important to raise a RecordNotFound error.
|
||||
def find_resource
|
||||
permalink = params[:id] || params[:enterprise_group_id]
|
||||
EnterpriseGroup.find_by!(permalink:)
|
||||
EnterpriseGroup.find_by!(permalink: permalink)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -16,8 +16,7 @@ module Admin
|
||||
@enterprise_relationship = EnterpriseRelationship.new enterprise_relationship_params
|
||||
|
||||
if @enterprise_relationship.save
|
||||
render plain: Api::Admin::EnterpriseRelationshipSerializer
|
||||
.new(@enterprise_relationship).to_json
|
||||
render plain: Api::Admin::EnterpriseRelationshipSerializer.new(@enterprise_relationship).to_json
|
||||
else
|
||||
render status: :bad_request,
|
||||
json: { errors: @enterprise_relationship.errors.full_messages.join(', ') }
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
module Admin
|
||||
class EnterpriseRolesController < Admin::ResourceController
|
||||
def index
|
||||
@enterprise_roles, @users, @all_enterprises = Admin::EnterpriseRolesQuery.query
|
||||
@my_enterprises = @all_enterprises
|
||||
@enterprise_roles = EnterpriseRole.by_user_email
|
||||
@users = Spree::User.order('spree_users.email')
|
||||
@my_enterprises = @all_enterprises = Enterprise.by_name
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
@@ -38,7 +38,7 @@ module Admin
|
||||
format.html
|
||||
format.json {
|
||||
render_as_json @collection, ams_prefix: params[:ams_prefix],
|
||||
spree_current_user:
|
||||
spree_current_user: spree_current_user
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -47,12 +47,12 @@ module Admin
|
||||
@object = Enterprise.where(permalink: params[:id]).
|
||||
includes(users: [:ship_address, :bill_address]).first
|
||||
@object.build_custom_tab if @object.custom_tab.nil?
|
||||
return unless params[:stimulus]
|
||||
|
||||
@enterprise.is_primary_producer = params[:is_primary_producer]
|
||||
@enterprise.sells = params[:enterprise_sells]
|
||||
render cable_ready: cable_car.morph("#side_menu", partial("admin/shared/side_menu"))
|
||||
.morph("#permalink", partial("admin/enterprises/form/permalink"))
|
||||
if params[:stimulus]
|
||||
@enterprise.is_primary_producer = params[:is_primary_producer]
|
||||
@enterprise.sells = params[:enterprise_sells]
|
||||
render cable_ready: cable_car.morph("#side_menu", partial("admin/shared/side_menu"))
|
||||
.morph("#permalink", partial("admin/enterprises/form/permalink"))
|
||||
end
|
||||
end
|
||||
|
||||
def welcome
|
||||
@@ -63,7 +63,6 @@ module Admin
|
||||
tag_rules_attributes = params[object_name].delete :tag_rules_attributes
|
||||
update_tag_rules(tag_rules_attributes) if tag_rules_attributes.present?
|
||||
update_enterprise_notifications
|
||||
update_vouchers
|
||||
|
||||
delete_custom_tab if params[:custom_tab] == 'false'
|
||||
|
||||
@@ -73,7 +72,7 @@ module Admin
|
||||
format.html { redirect_to location_after_save }
|
||||
format.js { render layout: false }
|
||||
format.json {
|
||||
render_as_json @object, ams_prefix: 'index', spree_current_user:
|
||||
render_as_json @object, ams_prefix: 'index', spree_current_user: spree_current_user
|
||||
}
|
||||
end
|
||||
else
|
||||
@@ -93,7 +92,7 @@ module Admin
|
||||
return render :welcome, layout: "spree/layouts/bare_admin"
|
||||
end
|
||||
|
||||
attributes = { sells: register_params[:sells], visible: "only_through_links" }
|
||||
attributes = { sells: register_params[:sells], visible: true }
|
||||
|
||||
if @enterprise.update(attributes)
|
||||
flash[:success] = I18n.t(:enterprise_register_success_notice, enterprise: @enterprise.name)
|
||||
@@ -122,12 +121,8 @@ module Admin
|
||||
def for_order_cycle
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render(
|
||||
json: @collection,
|
||||
each_serializer: Api::Admin::ForOrderCycle::EnterpriseSerializer,
|
||||
order_cycle: @order_cycle,
|
||||
spree_current_user:
|
||||
)
|
||||
render json: @collection,
|
||||
each_serializer: Api::Admin::ForOrderCycle::EnterpriseSerializer, order_cycle: @order_cycle, spree_current_user: spree_current_user
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -136,7 +131,7 @@ module Admin
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render_as_json @collection, ams_prefix: params[:ams_prefix] || 'basic',
|
||||
spree_current_user:
|
||||
spree_current_user: spree_current_user
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -183,7 +178,9 @@ module Admin
|
||||
when :for_order_cycle
|
||||
@order_cycle = OrderCycle.find_by(id: params[:order_cycle_id]) if params[:order_cycle_id]
|
||||
coordinator = Enterprise.find_by(id: params[:coordinator_id]) if params[:coordinator_id]
|
||||
@order_cycle ||= OrderCycle.new(coordinator:) if coordinator.present?
|
||||
if @order_cycle.nil? && coordinator.present?
|
||||
@order_cycle = OrderCycle.new(coordinator: coordinator)
|
||||
end
|
||||
|
||||
enterprises = OpenFoodNetwork::OrderCyclePermissions.new(spree_current_user, @order_cycle)
|
||||
.visible_enterprises
|
||||
@@ -264,44 +261,32 @@ module Admin
|
||||
def update_enterprise_notifications
|
||||
user_id = params[:receives_notifications].to_i
|
||||
|
||||
return unless user_id.positive? && @enterprise.user_ids.include?(user_id)
|
||||
|
||||
@enterprise.update_contact(user_id)
|
||||
end
|
||||
|
||||
def update_vouchers
|
||||
params_voucher_ids = params[:enterprise][:voucher_ids].to_a.map(&:to_i)
|
||||
voucher_ids = @enterprise.vouchers.map(&:id)
|
||||
deleted_voucher_ids = @enterprise.vouchers.only_deleted.map(&:id)
|
||||
|
||||
vouchers_to_destroy = voucher_ids - params_voucher_ids
|
||||
Voucher.where(id: vouchers_to_destroy).destroy_all if vouchers_to_destroy.present?
|
||||
|
||||
vouchers_to_restore = deleted_voucher_ids.intersection(params_voucher_ids)
|
||||
Voucher.restore(vouchers_to_restore) if vouchers_to_restore.present?
|
||||
if user_id.positive? && @enterprise.user_ids.include?(user_id)
|
||||
@enterprise.update_contact(user_id)
|
||||
end
|
||||
end
|
||||
|
||||
def create_calculator_for(rule, attrs)
|
||||
return unless attrs[:calculator_type].present? && attrs[:calculator_attributes].present?
|
||||
|
||||
rule.update(calculator_type: attrs[:calculator_type])
|
||||
attrs[:calculator_attributes].merge!( id: rule.calculator.id )
|
||||
if attrs[:calculator_type].present? && attrs[:calculator_attributes].present?
|
||||
rule.update(calculator_type: attrs[:calculator_type])
|
||||
attrs[:calculator_attributes].merge!( id: rule.calculator.id )
|
||||
end
|
||||
end
|
||||
|
||||
def check_can_change_bulk_sells
|
||||
return if spree_current_user.admin?
|
||||
|
||||
params[:sets_enterprise_set][:collection_attributes].each do |_i, enterprise_params|
|
||||
unless spree_current_user == Enterprise.find_by(id: enterprise_params[:id]).owner
|
||||
enterprise_params.delete :sells
|
||||
unless spree_current_user.admin?
|
||||
params[:sets_enterprise_set][:collection_attributes].each do |_i, enterprise_params|
|
||||
unless spree_current_user == Enterprise.find_by(id: enterprise_params[:id]).owner
|
||||
enterprise_params.delete :sells
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def check_can_change_sells
|
||||
return if spree_current_user.admin? || spree_current_user == @enterprise.owner
|
||||
|
||||
enterprise_params.delete :sells
|
||||
unless spree_current_user.admin? || spree_current_user == @enterprise.owner
|
||||
enterprise_params.delete :sells
|
||||
end
|
||||
end
|
||||
|
||||
def override_owner
|
||||
@@ -309,31 +294,31 @@ module Admin
|
||||
end
|
||||
|
||||
def override_sells
|
||||
return if spree_current_user.admin?
|
||||
|
||||
has_hub = spree_current_user.owned_enterprises.is_hub.any?
|
||||
new_enterprise_is_producer = Enterprise.new(enterprise_params).is_primary_producer
|
||||
enterprise_params[:sells] = has_hub && !new_enterprise_is_producer ? 'any' : 'none'
|
||||
unless spree_current_user.admin?
|
||||
has_hub = spree_current_user.owned_enterprises.is_hub.any?
|
||||
new_enterprise_is_producer = Enterprise.new(enterprise_params).is_primary_producer
|
||||
enterprise_params[:sells] = has_hub && !new_enterprise_is_producer ? 'any' : 'none'
|
||||
end
|
||||
end
|
||||
|
||||
def check_can_change_owner
|
||||
return if ( spree_current_user == @enterprise.owner ) || spree_current_user.admin?
|
||||
|
||||
enterprise_params.delete :owner_id
|
||||
end
|
||||
|
||||
def check_can_change_bulk_owner
|
||||
return if spree_current_user.admin?
|
||||
|
||||
bulk_params[:collection_attributes].each do |_i, enterprise_params|
|
||||
unless ( spree_current_user == @enterprise.owner ) || spree_current_user.admin?
|
||||
enterprise_params.delete :owner_id
|
||||
end
|
||||
end
|
||||
|
||||
def check_can_change_managers
|
||||
return if ( spree_current_user == @enterprise.owner ) || spree_current_user.admin?
|
||||
def check_can_change_bulk_owner
|
||||
unless spree_current_user.admin?
|
||||
bulk_params[:collection_attributes].each do |_i, enterprise_params|
|
||||
enterprise_params.delete :owner_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
enterprise_params.delete :user_ids
|
||||
def check_can_change_managers
|
||||
unless ( spree_current_user == @enterprise.owner ) || spree_current_user.admin?
|
||||
enterprise_params.delete :user_ids
|
||||
end
|
||||
end
|
||||
|
||||
def strip_new_properties
|
||||
|
||||
@@ -2,13 +2,6 @@
|
||||
|
||||
module Admin
|
||||
class OidcSettingsController < Spree::Admin::BaseController
|
||||
def index
|
||||
@account = spree_current_user.oidc_account
|
||||
end
|
||||
|
||||
def destroy
|
||||
spree_current_user.oidc_account&.destroy
|
||||
redirect_to admin_oidc_settings_path
|
||||
end
|
||||
def index; end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -48,7 +48,7 @@ module Admin
|
||||
@order_cycle_form = OrderCycleForm.new(@order_cycle, order_cycle_params, spree_current_user)
|
||||
|
||||
if @order_cycle_form.save
|
||||
flash[:success] = t('.success')
|
||||
flash[:notice] = I18n.t(:order_cycles_create_notice)
|
||||
render json: { success: true,
|
||||
edit_path: main_app.admin_order_cycle_incoming_path(@order_cycle) }
|
||||
else
|
||||
@@ -66,7 +66,7 @@ module Admin
|
||||
if @order_cycle_form.save
|
||||
update_nil_subscription_line_items_price_estimate(@order_cycle)
|
||||
respond_to do |format|
|
||||
flash[:success] = t('.success') if params[:reloading] == '1'
|
||||
flash[:notice] = I18n.t(:order_cycles_update_notice) if params[:reloading] == '1'
|
||||
format.html { redirect_to_after_update_path }
|
||||
format.json { render json: { success: true } }
|
||||
end
|
||||
@@ -118,7 +118,7 @@ module Admin
|
||||
@order_cycle = OrderCycle.find params[:id]
|
||||
@order_cycle.clone!
|
||||
redirect_to main_app.admin_order_cycles_path,
|
||||
flash: { success: t('.success', name: @order_cycle.name) }
|
||||
notice: I18n.t(:order_cycles_clone_notice, name: @order_cycle.name)
|
||||
end
|
||||
|
||||
# Send notifications to all producers who are part of the order cycle
|
||||
@@ -126,7 +126,7 @@ module Admin
|
||||
OrderCycleNotificationJob.perform_later params[:id].to_i
|
||||
|
||||
redirect_to main_app.admin_order_cycles_path,
|
||||
flash: { success: t('.success') }
|
||||
notice: I18n.t(:order_cycles_email_to_producers_notice)
|
||||
end
|
||||
|
||||
protected
|
||||
@@ -182,17 +182,17 @@ module Admin
|
||||
end
|
||||
|
||||
def load_data_for_index
|
||||
return unless json_request?
|
||||
|
||||
# Split ransack params into all those that currently exist and new ones
|
||||
# to limit returned ocs to recent or undated
|
||||
orders_close_at_gt = raw_params[:q]&.delete(:orders_close_at_gt) || 31.days.ago
|
||||
raw_params[:q] = {
|
||||
g: [raw_params.delete(:q) || {}, { m: 'or',
|
||||
orders_close_at_gt:,
|
||||
orders_close_at_null: true }]
|
||||
}
|
||||
@collection = collection
|
||||
if json_request?
|
||||
# Split ransack params into all those that currently exist and new ones
|
||||
# to limit returned ocs to recent or undated
|
||||
orders_close_at_gt = raw_params[:q]&.delete(:orders_close_at_gt) || 31.days.ago
|
||||
raw_params[:q] = {
|
||||
g: [raw_params.delete(:q) || {}, { m: 'or',
|
||||
orders_close_at_gt: orders_close_at_gt,
|
||||
orders_close_at_null: true }]
|
||||
}
|
||||
@collection = collection
|
||||
end
|
||||
end
|
||||
|
||||
def redirect_to_after_update_path
|
||||
@@ -245,10 +245,10 @@ module Admin
|
||||
|
||||
order_cycle_params.delete :coordinator_id
|
||||
|
||||
return if Enterprise.managed_by(spree_current_user).include?(@order_cycle.coordinator)
|
||||
|
||||
order_cycle_params.delete_if do |k, _v|
|
||||
[:name, :orders_open_at, :orders_close_at].include? k.to_sym
|
||||
unless Enterprise.managed_by(spree_current_user).include?(@order_cycle.coordinator)
|
||||
order_cycle_params.delete_if do |k, _v|
|
||||
[:name, :orders_open_at, :orders_close_at].include? k.to_sym
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -37,14 +37,8 @@ module Admin
|
||||
end
|
||||
|
||||
def reset_absent_products
|
||||
@importer = ProductImport::ProductImporter.new(
|
||||
File.new(file_path),
|
||||
spree_current_user,
|
||||
import_into: params[:import_into],
|
||||
enterprises_to_reset: params[:enterprises_to_reset],
|
||||
updated_ids: params[:updated_ids],
|
||||
settings: params[:settings]
|
||||
)
|
||||
@importer = ProductImport::ProductImporter.new(File.new(file_path),
|
||||
spree_current_user, import_into: params[:import_into], enterprises_to_reset: params[:enterprises_to_reset], updated_ids: params[:updated_ids], settings: params[:settings])
|
||||
|
||||
if params.key?(:enterprises_to_reset) && params.key?(:updated_ids)
|
||||
@importer.reset_absent(params[:updated_ids])
|
||||
@@ -56,19 +50,14 @@ module Admin
|
||||
private
|
||||
|
||||
def validate_upload_presence
|
||||
return if params[:file] || (params[:filepath] && File.exist?(params[:filepath]))
|
||||
|
||||
redirect_to '/admin/product_import', notice: I18n.t(:product_import_file_not_found_notice)
|
||||
unless params[:file] || (params[:filepath] && File.exist?(params[:filepath]))
|
||||
redirect_to '/admin/product_import', notice: I18n.t(:product_import_file_not_found_notice)
|
||||
end
|
||||
end
|
||||
|
||||
def process_data(method)
|
||||
@importer = ProductImport::ProductImporter.new(
|
||||
File.new(file_path),
|
||||
spree_current_user,
|
||||
start: params[:start],
|
||||
end: params[:end],
|
||||
settings: params[:settings]
|
||||
)
|
||||
@importer = ProductImport::ProductImporter.new(File.new(file_path),
|
||||
spree_current_user, start: params[:start], end: params[:end], settings: params[:settings])
|
||||
|
||||
begin
|
||||
@importer.public_send("#{method}_entries")
|
||||
@@ -90,11 +79,11 @@ module Admin
|
||||
end
|
||||
|
||||
def check_spreadsheet_has_data(importer)
|
||||
return if importer.item_count
|
||||
|
||||
redirect_to '/admin/product_import',
|
||||
notice: I18n.t(:product_import_no_data_in_spreadsheet_notice)
|
||||
true
|
||||
unless importer.item_count
|
||||
redirect_to '/admin/product_import',
|
||||
notice: I18n.t(:product_import_no_data_in_spreadsheet_notice)
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
def save_uploaded_file(upload)
|
||||
@@ -139,8 +128,7 @@ module Admin
|
||||
end
|
||||
|
||||
def raise_invalid_file_path
|
||||
redirect_to '/admin/product_import',
|
||||
notice: I18n.t(:product_import_no_data_in_spreadsheet_notice)
|
||||
redirect_to '/admin/product_import', notice: I18n.t(:product_import_no_data_in_spreadsheet_notice)
|
||||
raise 'Invalid File Path'
|
||||
end
|
||||
TEMP_FILE_PATH_REGEX = %r{^/tmp/product_import[A-Za-z0-9-]*/import\.csv$}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Admin
|
||||
class ProductsV3Controller < Spree::Admin::BaseController
|
||||
class ProductsController < Spree::Admin::BaseController
|
||||
def index; end
|
||||
end
|
||||
end
|
||||
@@ -13,7 +13,7 @@ module Admin
|
||||
if @proxy_order.cancel
|
||||
render_as_json @proxy_order
|
||||
else
|
||||
render json: { errors: [t('.could_not_cancel_the_order')] },
|
||||
render json: { errors: [t('admin.proxy_orders.cancel.could_not_cancel_the_order')] },
|
||||
status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
@@ -22,7 +22,7 @@ module Admin
|
||||
if @proxy_order.resume
|
||||
render_as_json @proxy_order
|
||||
else
|
||||
render json: { errors: [t('.could_not_resume_the_order')] },
|
||||
render json: { errors: [t('admin.proxy_orders.resume.could_not_resume_the_order')] },
|
||||
status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
@@ -21,19 +21,25 @@ module Admin
|
||||
|
||||
def show
|
||||
@report = report_class.new(spree_current_user, params, render: render_data?)
|
||||
@rendering_options = rendering_options # also stores user preferences
|
||||
|
||||
if render_data?
|
||||
render_in_background
|
||||
if params[:report_format].present?
|
||||
export_report
|
||||
else
|
||||
show_report
|
||||
end
|
||||
rescue Timeout::Error
|
||||
render_timeout_error
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def export_report
|
||||
send_data render_report_as(report_format), filename: report_filename
|
||||
end
|
||||
|
||||
def show_report
|
||||
assign_view_data
|
||||
@table = render_report_as(:html) if render_data?
|
||||
render "show"
|
||||
end
|
||||
|
||||
@@ -42,40 +48,53 @@ module Admin
|
||||
@report_subtypes = report_subtypes
|
||||
@report_subtype = report_subtype
|
||||
@report_title = report_title
|
||||
@rendering_options = rendering_options
|
||||
@data = Reporting::FrontendData.new(spree_current_user)
|
||||
|
||||
variant_id_in = params[:variant_id_in]&.compact_blank
|
||||
load_selected_variant if variant_id_in.present?
|
||||
end
|
||||
|
||||
# Orders and Fulfillment Reports include a per product filter, load any selected product
|
||||
def load_selected_variant
|
||||
variant = Spree::Variant.find(params[:variant_id_in][0])
|
||||
@variant_serialized = Api::Admin::VariantSerializer.new(variant)
|
||||
end
|
||||
|
||||
def render_data?
|
||||
request.post?
|
||||
end
|
||||
|
||||
def render_in_background
|
||||
cable_ready[ScopedChannel.for_id(params[:uuid])]
|
||||
.inner_html(
|
||||
selector: "#report-table",
|
||||
html: render_to_string(partial: "admin/reports/loading")
|
||||
).scroll_into_view(
|
||||
selector: "#report-table",
|
||||
block: "start"
|
||||
).broadcast
|
||||
def render_report_as(format)
|
||||
if OpenFoodNetwork::FeatureToggle.enabled?(:background_reports, spree_current_user)
|
||||
@blob = ReportBlob.create_for_upload_later!(report_filename)
|
||||
ReportJob.perform_later(
|
||||
report_class, spree_current_user, params, format, @blob
|
||||
)
|
||||
Timeout.timeout(max_wait_time) do
|
||||
sleep 1 until @blob.content_stored?
|
||||
end
|
||||
|
||||
ReportJob.perform_later(
|
||||
report_class:, user: spree_current_user, params:,
|
||||
format: report_format,
|
||||
filename: report_filename,
|
||||
channel: ScopedChannel.for_id(params[:uuid]),
|
||||
)
|
||||
# This result has been rendered by Rails in safe mode already.
|
||||
@blob.result.html_safe # rubocop:disable Rails/OutputSafety
|
||||
else
|
||||
@report.render_as(format)
|
||||
end
|
||||
end
|
||||
|
||||
head :no_content
|
||||
def render_timeout_error
|
||||
assign_view_data
|
||||
if @blob
|
||||
@error = ".report_taking_longer_html"
|
||||
@error_url = @blob.expiring_service_url
|
||||
else
|
||||
@error = ".report_taking_longer"
|
||||
@error_url = ""
|
||||
end
|
||||
render "show"
|
||||
end
|
||||
|
||||
def max_wait_time
|
||||
# This value is used by rack-timeout and nginx, usually 30 seconds in
|
||||
# staging and production:
|
||||
server_timeout = ENV.fetch("RACK_TIMEOUT_SERVICE_TIMEOUT", "15").to_f
|
||||
|
||||
# Zero disables the timeout:
|
||||
return 0 if server_timeout.zero?
|
||||
|
||||
# We want to time out earlier than nginx:
|
||||
server_timeout - 2.seconds
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,6 +24,18 @@ module Admin
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @object.update(permitted_resource_params)
|
||||
flash[:success] = flash_message_for(@object, :successfully_updated)
|
||||
respond_with(@object) do |format|
|
||||
format.html { redirect_to location_after_save }
|
||||
format.js { render layout: false }
|
||||
end
|
||||
else
|
||||
respond_with(@object)
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@object.attributes = permitted_resource_params
|
||||
if @object.save
|
||||
@@ -37,21 +49,9 @@ module Admin
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @object.update(permitted_resource_params)
|
||||
flash[:success] = flash_message_for(@object, :successfully_updated)
|
||||
respond_with(@object) do |format|
|
||||
format.html { redirect_to location_after_save }
|
||||
format.js { render layout: false }
|
||||
end
|
||||
else
|
||||
respond_with(@object)
|
||||
end
|
||||
end
|
||||
|
||||
def update_positions
|
||||
params[:positions].each do |id, index|
|
||||
model_class.where(id:).update_all(position: index)
|
||||
model_class.where(id: id).update_all(position: index)
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'open_food_network/permissions'
|
||||
require 'order_management/subscriptions/proxy_order_syncer'
|
||||
|
||||
module Admin
|
||||
class SchedulesController < Admin::ResourceController
|
||||
include PaperTrailLogging
|
||||
|
||||
before_action :adapt_params, only: [:update]
|
||||
before_action :editable_order_cycle_ids_for_create, only: [:create]
|
||||
before_action :editable_order_cycle_ids_for_update, only: [:update]
|
||||
before_action :check_dependent_subscriptions, only: [:destroy]
|
||||
|
||||
after_action :sync_subscriptions_for_update, only: :update
|
||||
|
||||
respond_to :json
|
||||
|
||||
OVERRIDE_RESPONSE = { json: {
|
||||
respond_override create: { json: {
|
||||
success: lambda {
|
||||
render_as_json @schedule,
|
||||
editable_schedule_ids: permissions.editable_schedules.pluck(:id)
|
||||
@@ -22,10 +25,17 @@ module Admin
|
||||
render json: { errors: @schedule.errors.full_messages },
|
||||
status: :unprocessable_entity
|
||||
}
|
||||
} }.freeze
|
||||
|
||||
respond_override create: OVERRIDE_RESPONSE
|
||||
respond_override update: OVERRIDE_RESPONSE
|
||||
} }
|
||||
respond_override update: { json: {
|
||||
success: lambda {
|
||||
render_as_json @schedule,
|
||||
editable_schedule_ids: permissions.editable_schedules.pluck(:id)
|
||||
},
|
||||
failure: lambda {
|
||||
render json: { errors: @schedule.errors.full_messages },
|
||||
status: :unprocessable_entity
|
||||
}
|
||||
} }
|
||||
|
||||
def index
|
||||
respond_to do |format|
|
||||
@@ -40,23 +50,22 @@ module Admin
|
||||
end
|
||||
|
||||
def create
|
||||
@schedule_form = ScheduleForm.new(params, spree_current_user, @schedule)
|
||||
return respond_with(@schedule) if params[:order_cycle_ids].blank?
|
||||
|
||||
@schedule.attributes = permitted_resource_params
|
||||
|
||||
if @schedule.save
|
||||
@schedule.order_cycle_ids = params[:order_cycle_ids]
|
||||
@schedule.save!
|
||||
|
||||
if @schedule_form.save
|
||||
flash[:success] = flash_message_for(@schedule, :successfully_created)
|
||||
@existing_order_cycle_ids = []
|
||||
sync_subscriptions_for_create
|
||||
|
||||
flash[:success] = flash_message_for(@schedule, :successfully_created)
|
||||
end
|
||||
|
||||
respond_with(@schedule)
|
||||
end
|
||||
|
||||
def update
|
||||
@existing_order_cycle_ids = @schedule.order_cycle_ids
|
||||
@object = ScheduleForm.new(params, spree_current_user, @schedule)
|
||||
super
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def collection
|
||||
@@ -87,6 +96,37 @@ module Admin
|
||||
params[:schedule][:order_cycle_ids] = params[:order_cycle_ids]
|
||||
end
|
||||
|
||||
def editable_order_cycle_ids_for_create
|
||||
return unless params[:order_cycle_ids]
|
||||
|
||||
@existing_order_cycle_ids = []
|
||||
result = editable_order_cycles(params[:order_cycle_ids])
|
||||
|
||||
params[:order_cycle_ids] = result
|
||||
end
|
||||
|
||||
def editable_order_cycle_ids_for_update
|
||||
return unless params[:schedule][:order_cycle_ids]
|
||||
|
||||
@existing_order_cycle_ids = @schedule.order_cycle_ids
|
||||
result = editable_order_cycles(params[:schedule][:order_cycle_ids])
|
||||
|
||||
params[:schedule][:order_cycle_ids] = result
|
||||
@schedule.order_cycle_ids = result
|
||||
end
|
||||
|
||||
def editable_order_cycles(requested)
|
||||
permitted = OrderCycle
|
||||
.where(id: params[:order_cycle_ids] | @existing_order_cycle_ids)
|
||||
.merge(OrderCycle.managed_by(spree_current_user))
|
||||
.pluck(:id)
|
||||
result = @existing_order_cycle_ids
|
||||
result |= (requested & permitted) # add any requested & permitted ids
|
||||
# remove any existing and permitted ids that were not specifically requested
|
||||
result -= ((result & permitted) - requested)
|
||||
result
|
||||
end
|
||||
|
||||
def check_dependent_subscriptions
|
||||
return if Subscription.where(schedule_id: @schedule).empty?
|
||||
|
||||
@@ -100,14 +140,14 @@ module Admin
|
||||
@permissions = OpenFoodNetwork::Permissions.new(spree_current_user)
|
||||
end
|
||||
|
||||
def sync_subscriptions_for_create
|
||||
return unless params[:order_cycle_ids]
|
||||
def sync_subscriptions_for_update
|
||||
return unless params[:schedule][:order_cycle_ids] && @object.errors.blank?
|
||||
|
||||
sync_subscriptions
|
||||
end
|
||||
|
||||
def sync_subscriptions_for_update
|
||||
return unless params[:schedule][:order_cycle_ids] && @schedule.errors.blank?
|
||||
def sync_subscriptions_for_create
|
||||
return unless params[:order_cycle_ids]
|
||||
|
||||
sync_subscriptions
|
||||
end
|
||||
@@ -115,7 +155,6 @@ module Admin
|
||||
def sync_subscriptions
|
||||
removed_ids = @existing_order_cycle_ids - @schedule.order_cycle_ids
|
||||
new_ids = @schedule.order_cycle_ids - @existing_order_cycle_ids
|
||||
|
||||
return unless removed_ids.any? || new_ids.any?
|
||||
|
||||
subscriptions = Subscription.where(schedule_id: @schedule)
|
||||
|
||||
@@ -21,7 +21,7 @@ module Admin
|
||||
def update
|
||||
Spree::Config.set(settings_params.to_h)
|
||||
resource = t('admin.controllers.stripe_connect_settings.resource')
|
||||
flash[:success] = t(:successfully_updated, resource:)
|
||||
flash[:success] = t(:successfully_updated, resource: resource)
|
||||
redirect_to_edit
|
||||
end
|
||||
|
||||
|
||||
@@ -18,8 +18,7 @@ module Admin
|
||||
if view_context.subscriptions_setup_complete?(@shops)
|
||||
@order_cycles = OrderCycle.joins(:schedules).managed_by(spree_current_user)
|
||||
.includes([:distributors, :cached_incoming_exchanges])
|
||||
@payment_methods = Spree::PaymentMethod.managed_by(spree_current_user)
|
||||
.includes(:taggings)
|
||||
@payment_methods = Spree::PaymentMethod.managed_by(spree_current_user).includes(:taggings)
|
||||
@payment_method_tags = payment_method_tags_by_id
|
||||
@shipping_methods = Spree::ShippingMethod.managed_by(spree_current_user)
|
||||
else
|
||||
@@ -101,8 +100,7 @@ module Admin
|
||||
end
|
||||
|
||||
def load_shops
|
||||
@shops = Enterprise.managed_by(spree_current_user)
|
||||
.is_distributor.where(enable_subscriptions: true)
|
||||
@shops = Enterprise.managed_by(spree_current_user).is_distributor.where(enable_subscriptions: true)
|
||||
end
|
||||
|
||||
def load_form_data
|
||||
@@ -141,9 +139,7 @@ module Admin
|
||||
@open_orders_to_keep = @subscription.proxy_orders.placed_and_open.pluck(:id)
|
||||
return if @open_orders_to_keep.empty? || params[:open_orders] == 'keep'
|
||||
|
||||
render json: {
|
||||
errors: { open_orders: t('admin.subscriptions.confirm_cancel_open_orders_msg') }
|
||||
},
|
||||
render json: { errors: { open_orders: t('admin.subscriptions.confirm_cancel_open_orders_msg') } },
|
||||
status: :conflict
|
||||
end
|
||||
|
||||
@@ -151,9 +147,7 @@ module Admin
|
||||
return if params[:canceled_orders] == 'notified'
|
||||
return if @subscription.proxy_orders.active.canceled.empty?
|
||||
|
||||
render json: {
|
||||
errors: { canceled_orders: t('admin.subscriptions.resume_canceled_orders_msg') }
|
||||
},
|
||||
render json: { errors: { canceled_orders: t('admin.subscriptions.resume_canceled_orders_msg') } },
|
||||
status: :conflict
|
||||
end
|
||||
|
||||
|
||||
@@ -9,33 +9,22 @@ module Admin
|
||||
end
|
||||
|
||||
def create
|
||||
@voucher = Voucher.new(
|
||||
permitted_resource_params.merge(enterprise: @enterprise)
|
||||
)
|
||||
voucher_params = permitted_resource_params.merge(enterprise: @enterprise)
|
||||
@voucher = Voucher.create(voucher_params)
|
||||
|
||||
if @voucher.save
|
||||
flash[:success] = I18n.t(:successfully_created, resource: "Voucher")
|
||||
redirect_to edit_admin_enterprise_path(@enterprise, anchor: :vouchers_panel)
|
||||
redirect_to(
|
||||
"#{edit_admin_enterprise_path(@enterprise)}#vouchers_panel",
|
||||
flash: { success: flash_message_for(@voucher, :successfully_created) }
|
||||
)
|
||||
else
|
||||
render_error
|
||||
flash[:error] = @voucher.errors.full_messages.to_sentence
|
||||
render :new
|
||||
end
|
||||
rescue ActiveRecord::SubclassNotFound
|
||||
@voucher.errors.add(:type)
|
||||
render_error
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
# Rails unique validation doesn't work with soft deleted object, so we rescue the database
|
||||
# exception to display a nice message to the user
|
||||
@voucher.errors.add(:code, :taken)
|
||||
render_error
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def render_error
|
||||
flash[:error] = @voucher.errors.full_messages.to_sentence
|
||||
render :new
|
||||
end
|
||||
|
||||
def load_enterprise
|
||||
@enterprise = OpenFoodNetwork::Permissions
|
||||
.new(spree_current_user)
|
||||
@@ -44,7 +33,7 @@ module Admin
|
||||
end
|
||||
|
||||
def permitted_resource_params
|
||||
params.require(:voucher).permit(:code, :amount, :type)
|
||||
params.require(:voucher).permit(:code, :amount)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@ module Api
|
||||
skip_authorization_check only: :index
|
||||
|
||||
def index
|
||||
@customers = current_api_user.customers.visible
|
||||
@customers = current_api_user.customers
|
||||
render json: @customers, each_serializer: CustomerSerializer
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'api/admin/enterprise_serializer'
|
||||
|
||||
module Api
|
||||
module V0
|
||||
class EnterpriseAttachmentController < Api::V0::BaseController
|
||||
@@ -19,7 +21,7 @@ module Api
|
||||
@enterprise.update!(attachment_name => nil)
|
||||
render json: @enterprise,
|
||||
serializer: Admin::EnterpriseSerializer,
|
||||
spree_current_user:
|
||||
spree_current_user: spree_current_user
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
@@ -74,7 +74,7 @@ module Api
|
||||
end
|
||||
|
||||
def override_visible
|
||||
enterprise_params[:visible] = "only_through_links"
|
||||
enterprise_params[:visible] = false
|
||||
end
|
||||
|
||||
def enterprise_params
|
||||
|
||||
@@ -5,6 +5,11 @@ module Api
|
||||
class OrdersController < Api::V0::BaseController
|
||||
include PaginationData
|
||||
|
||||
def show
|
||||
authorize! :read, order
|
||||
render json: order, serializer: Api::OrderDetailedSerializer, current_order: order
|
||||
end
|
||||
|
||||
def index
|
||||
authorize! :admin, Spree::Order
|
||||
|
||||
@@ -21,11 +26,6 @@ module Api
|
||||
}
|
||||
end
|
||||
|
||||
def show
|
||||
authorize! :read, order
|
||||
render json: order, serializer: Api::OrderDetailedSerializer, current_order: order
|
||||
end
|
||||
|
||||
def update
|
||||
authorize! :admin, order
|
||||
|
||||
|
||||
@@ -10,10 +10,12 @@ module Api
|
||||
respond_to :json
|
||||
DEFAULT_PER_PAGE = 15
|
||||
|
||||
before_action :set_default_available_on, only: :create
|
||||
|
||||
skip_authorization_check only: [:show, :bulk_products, :overridable]
|
||||
|
||||
def show
|
||||
@product = product_finder.find_product
|
||||
@product = find_product(params[:id])
|
||||
render json: @product, serializer: Api::Admin::ProductSerializer
|
||||
end
|
||||
|
||||
@@ -21,16 +23,21 @@ module Api
|
||||
authorize! :create, Spree::Product
|
||||
@product = Spree::Product.new(product_params)
|
||||
|
||||
if @product.save
|
||||
render json: @product, serializer: Api::Admin::ProductSerializer, status: :created
|
||||
else
|
||||
invalid_resource!(@product)
|
||||
begin
|
||||
if @product.save
|
||||
render json: @product, serializer: Api::Admin::ProductSerializer, status: :created
|
||||
else
|
||||
invalid_resource!(@product)
|
||||
end
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
@product.permalink = nil
|
||||
retry
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
authorize! :update, Spree::Product
|
||||
@product = product_finder.find_product
|
||||
@product = find_product(params[:id])
|
||||
if @product.update(product_params)
|
||||
render json: @product, serializer: Api::Admin::ProductSerializer, status: :ok
|
||||
else
|
||||
@@ -40,20 +47,36 @@ module Api
|
||||
|
||||
def destroy
|
||||
authorize! :delete, Spree::Product
|
||||
@product = product_finder.find_product
|
||||
@product = find_product(params[:id])
|
||||
authorize! :delete, @product
|
||||
@product.destroy
|
||||
render json: @product, serializer: Api::Admin::ProductSerializer, status: :no_content
|
||||
end
|
||||
|
||||
def bulk_products
|
||||
@products = product_finder.bulk_products
|
||||
product_query = OpenFoodNetwork::Permissions.
|
||||
new(current_api_user).
|
||||
editable_products.
|
||||
merge(product_scope)
|
||||
|
||||
if params[:import_date].present?
|
||||
product_query = product_query.
|
||||
imported_on(params[:import_date]).
|
||||
group_by_products_id
|
||||
end
|
||||
|
||||
@products = product_query.
|
||||
ransack(query_params_with_defaults).
|
||||
result
|
||||
|
||||
render_paged_products @products
|
||||
end
|
||||
|
||||
def overridable
|
||||
@products = product_finder.paged_products_for_producers
|
||||
producer_ids = OpenFoodNetwork::Permissions.new(current_api_user).
|
||||
variant_override_producers.by_name.select('enterprises.id')
|
||||
|
||||
@products = paged_products_for_producers producer_ids
|
||||
|
||||
render_paged_products @products, ::Api::Admin::ProductSimpleSerializer
|
||||
end
|
||||
@@ -62,7 +85,7 @@ module Api
|
||||
#
|
||||
def clone
|
||||
authorize! :create, Spree::Product
|
||||
original_product = product_finder.find_product_to_be_cloned
|
||||
original_product = find_product(params[:product_id])
|
||||
authorize! :update, original_product
|
||||
|
||||
@product = original_product.duplicate
|
||||
@@ -72,8 +95,39 @@ module Api
|
||||
|
||||
private
|
||||
|
||||
def product_finder
|
||||
ProductScopeQuery.new(current_api_user, params)
|
||||
def find_product(id)
|
||||
product_scope.find_by!(permalink: id.to_s)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
product_scope.find(id)
|
||||
end
|
||||
|
||||
def product_scope
|
||||
if current_api_user.has_spree_role?("admin") || current_api_user.enterprises.present?
|
||||
scope = Spree::Product
|
||||
if params[:show_deleted]
|
||||
scope = scope.with_deleted
|
||||
end
|
||||
else
|
||||
scope = Spree::Product.active
|
||||
end
|
||||
|
||||
scope.includes(product_query_includes)
|
||||
end
|
||||
|
||||
def product_query_includes
|
||||
[
|
||||
image: { attachment_attachment: :blob },
|
||||
variants: [:default_price, :stock_locations, :stock_items, :variant_overrides]
|
||||
]
|
||||
end
|
||||
|
||||
def paged_products_for_producers(producer_ids)
|
||||
Spree::Product.where(nil).
|
||||
merge(product_scope).
|
||||
includes(variants: [:product, :default_price, :stock_items]).
|
||||
where(supplier_id: producer_ids).
|
||||
by_producer.by_name.
|
||||
ransack(params[:q]).result
|
||||
end
|
||||
|
||||
def render_paged_products(products, product_serializer = ::Api::Admin::ProductSerializer)
|
||||
@@ -90,10 +144,18 @@ module Api
|
||||
}
|
||||
end
|
||||
|
||||
def query_params_with_defaults
|
||||
(params[:q] || {}).reverse_merge(s: 'created_at desc')
|
||||
end
|
||||
|
||||
def product_params
|
||||
@product_params ||=
|
||||
params.permit(product: PermittedAttributes::Product.attributes)[:product].to_h
|
||||
end
|
||||
|
||||
def set_default_available_on
|
||||
product_params[:available_on] ||= Time.zone.now
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user