Pack up functionality done
This commit is contained in:
3
Gemfile
3
Gemfile
@@ -43,3 +43,6 @@ end
|
|||||||
|
|
||||||
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
||||||
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
||||||
|
|
||||||
|
|
||||||
|
gem "csv", "~> 3.1"
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ GEM
|
|||||||
byebug (11.0.1)
|
byebug (11.0.1)
|
||||||
concurrent-ruby (1.1.5)
|
concurrent-ruby (1.1.5)
|
||||||
crass (1.0.4)
|
crass (1.0.4)
|
||||||
|
csv (3.1.7)
|
||||||
erubi (1.8.0)
|
erubi (1.8.0)
|
||||||
ffi (1.11.1)
|
ffi (1.11.1)
|
||||||
globalid (0.4.2)
|
globalid (0.4.2)
|
||||||
@@ -134,6 +135,7 @@ PLATFORMS
|
|||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
bootsnap (>= 1.1.0)
|
bootsnap (>= 1.1.0)
|
||||||
byebug
|
byebug
|
||||||
|
csv (~> 3.1)
|
||||||
listen (>= 3.0.5, < 3.2)
|
listen (>= 3.0.5, < 3.2)
|
||||||
pg (>= 0.18, < 2.0)
|
pg (>= 0.18, < 2.0)
|
||||||
puma (~> 3.11)
|
puma (~> 3.11)
|
||||||
@@ -146,4 +148,4 @@ RUBY VERSION
|
|||||||
ruby 2.6.3p62
|
ruby 2.6.3p62
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
1.17.2
|
1.17.3
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
class GangsController < ApplicationController
|
class GangsController < ApplicationController
|
||||||
|
include ActionController::MimeResponds
|
||||||
|
before_action :set_gang, only: [:update, :backup]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
json_response Gang.all
|
json_response Gang.all
|
||||||
rescue StandardError
|
rescue StandardError
|
||||||
@@ -18,19 +21,40 @@ class GangsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
if params[:id]
|
@gang.update!(gang_params)
|
||||||
gang = Gang.find(params[:id])
|
|
||||||
gang.update!(gang_params)
|
|
||||||
json_response onboarded: true
|
json_response onboarded: true
|
||||||
else
|
rescue StandardError => err
|
||||||
error_response :bad_request
|
Rails.logger.error(err)
|
||||||
end
|
|
||||||
rescue StandardError
|
|
||||||
error_response :bad_request
|
error_response :bad_request
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def backup
|
||||||
|
csv_string = CSV.generate do |csv|
|
||||||
|
csv << [:homie_name, :money_amount, :work_amount, :description, :date, :deleted]
|
||||||
|
@gang.money_moves.each do |money_move|
|
||||||
|
csv << money_move.to_csv_row
|
||||||
|
end
|
||||||
|
|
||||||
|
@gang.works.each do |work|
|
||||||
|
csv << work.to_csv_row
|
||||||
|
end
|
||||||
|
end
|
||||||
|
send_data csv_string
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def set_gang
|
||||||
|
if params[:gang_id] || params[:id]
|
||||||
|
@gang = Gang.find(params[:id] || params[:gang_id])
|
||||||
|
else
|
||||||
|
error_response :bad_request
|
||||||
|
end
|
||||||
|
rescue StandardError => err
|
||||||
|
Rails.logger.error(err)
|
||||||
|
error_response :bad_request
|
||||||
|
end
|
||||||
|
|
||||||
def gang_params
|
def gang_params
|
||||||
params.require(:gang).permit :name,
|
params.require(:gang).permit :name,
|
||||||
:about,
|
:about,
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
class Gang < ApplicationRecord
|
class Gang < ApplicationRecord
|
||||||
has_many :homies
|
has_many :homies, class_name: "Homie"
|
||||||
|
has_many :money_moves, through: :homies
|
||||||
|
has_many :works, through: :homies
|
||||||
end
|
end
|
||||||
@@ -25,6 +25,17 @@ class MoneyMove < ApplicationRecord
|
|||||||
settle_record.save
|
settle_record.save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_csv_row
|
||||||
|
[homie.name,
|
||||||
|
amount,
|
||||||
|
0,
|
||||||
|
description,
|
||||||
|
created_at.strftime("%Y-%m-%d"),
|
||||||
|
deleted_at.present?.to_s].map do |element|
|
||||||
|
element.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
private
|
private
|
||||||
|
|
||||||
@@ -65,5 +76,6 @@ class MoneyMove < ApplicationRecord
|
|||||||
description: new_desc
|
description: new_desc
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,3 +1,14 @@
|
|||||||
class Work < ApplicationRecord
|
class Work < ApplicationRecord
|
||||||
belongs_to :homie
|
belongs_to :homie
|
||||||
|
|
||||||
|
def to_csv_row
|
||||||
|
[homie.name,
|
||||||
|
0,
|
||||||
|
amount,
|
||||||
|
description,
|
||||||
|
created_at.strftime("%Y-%m-%d"),
|
||||||
|
false].map do |element|
|
||||||
|
element.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
"proxy": "http://localhost:3001",
|
"proxy": "http://localhost:3001",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.19.0",
|
"axios": "^0.19.0",
|
||||||
|
"js-file-download": "^0.4.12",
|
||||||
"materialize-css": "^1.0.0",
|
"materialize-css": "^1.0.0",
|
||||||
"react": "^16.8.6",
|
"react": "^16.8.6",
|
||||||
"react-dom": "^16.8.6",
|
"react-dom": "^16.8.6",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {errorToast} from "../common/errorHelpers";
|
|||||||
import {withRouter} from 'react-router-dom';
|
import {withRouter} from 'react-router-dom';
|
||||||
import {GANGS} from "../RouteNames";
|
import {GANGS} from "../RouteNames";
|
||||||
import M from 'materialize-css';
|
import M from 'materialize-css';
|
||||||
|
import fileDownload from 'js-file-download';
|
||||||
|
|
||||||
const GangDetails = (props) => {
|
const GangDetails = (props) => {
|
||||||
const gang = props.gang;
|
const gang = props.gang;
|
||||||
@@ -13,6 +14,17 @@ const GangDetails = (props) => {
|
|||||||
|
|
||||||
const disableSubmit = () => gangName.length === 0;
|
const disableSubmit = () => gangName.length === 0;
|
||||||
|
|
||||||
|
const getBackup = async () => {
|
||||||
|
try {
|
||||||
|
const response = await axios.get(`/api/gangs/${gang.id}/backup`);
|
||||||
|
const timestamp = Date.now();
|
||||||
|
const safeGangName = str.replace(/blue/g, "red");
|
||||||
|
fileDownload(response.data, `fil.csv`, 'text/csv')
|
||||||
|
} catch (e) {
|
||||||
|
console.log("EE ", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const updateGang = async () => {
|
const updateGang = async () => {
|
||||||
const updatedGang = {
|
const updatedGang = {
|
||||||
name: gangName
|
name: gangName
|
||||||
@@ -47,6 +59,15 @@ const GangDetails = (props) => {
|
|||||||
Make it done
|
Make it done
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<h1> Pack up </h1>
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
<Button onClick={getBackup}> Pack up </Button>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5555,6 +5555,11 @@ jest@24.7.1:
|
|||||||
import-local "^2.0.0"
|
import-local "^2.0.0"
|
||||||
jest-cli "^24.7.1"
|
jest-cli "^24.7.1"
|
||||||
|
|
||||||
|
js-file-download@^0.4.12:
|
||||||
|
version "0.4.12"
|
||||||
|
resolved "https://registry.yarnpkg.com/js-file-download/-/js-file-download-0.4.12.tgz#10c70ef362559a5b23cdbdc3bd6f399c3d91d821"
|
||||||
|
integrity sha512-rML+NkoD08p5Dllpjo0ffy4jRHeY6Zsapvr/W86N7E0yuzAO6qa5X9+xog6zQNlH102J7IXljNY2FtS6Lj3ucg==
|
||||||
|
|
||||||
js-levenshtein@^1.1.3:
|
js-levenshtein@^1.1.3:
|
||||||
version "1.1.6"
|
version "1.1.6"
|
||||||
resolved "https://registry.yarnpkg.com/js-levenshtein/-/js-levenshtein-1.1.6.tgz#c6cee58eb3550372df8deb85fad5ce66ce01d59d"
|
resolved "https://registry.yarnpkg.com/js-levenshtein/-/js-levenshtein-1.1.6.tgz#c6cee58eb3550372df8deb85fad5ce66ce01d59d"
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ Rails.application.routes.draw do
|
|||||||
resources :money_moves
|
resources :money_moves
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
get 'backup'
|
||||||
end
|
end
|
||||||
resources :work
|
resources :work
|
||||||
resources :chips, only: %i[index create destroy]
|
resources :chips, only: %i[index create destroy]
|
||||||
|
|||||||
Reference in New Issue
Block a user