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
|
||||
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
||||
|
||||
|
||||
gem "csv", "~> 3.1"
|
||||
|
||||
@@ -49,6 +49,7 @@ GEM
|
||||
byebug (11.0.1)
|
||||
concurrent-ruby (1.1.5)
|
||||
crass (1.0.4)
|
||||
csv (3.1.7)
|
||||
erubi (1.8.0)
|
||||
ffi (1.11.1)
|
||||
globalid (0.4.2)
|
||||
@@ -134,6 +135,7 @@ PLATFORMS
|
||||
DEPENDENCIES
|
||||
bootsnap (>= 1.1.0)
|
||||
byebug
|
||||
csv (~> 3.1)
|
||||
listen (>= 3.0.5, < 3.2)
|
||||
pg (>= 0.18, < 2.0)
|
||||
puma (~> 3.11)
|
||||
@@ -146,4 +148,4 @@ RUBY VERSION
|
||||
ruby 2.6.3p62
|
||||
|
||||
BUNDLED WITH
|
||||
1.17.2
|
||||
1.17.3
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
class GangsController < ApplicationController
|
||||
include ActionController::MimeResponds
|
||||
before_action :set_gang, only: [:update, :backup]
|
||||
|
||||
def index
|
||||
json_response Gang.all
|
||||
rescue StandardError
|
||||
@@ -18,19 +21,40 @@ class GangsController < ApplicationController
|
||||
end
|
||||
|
||||
def update
|
||||
if params[:id]
|
||||
gang = Gang.find(params[:id])
|
||||
gang.update!(gang_params)
|
||||
@gang.update!(gang_params)
|
||||
json_response onboarded: true
|
||||
else
|
||||
error_response :bad_request
|
||||
end
|
||||
rescue StandardError
|
||||
rescue StandardError => err
|
||||
Rails.logger.error(err)
|
||||
error_response :bad_request
|
||||
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
|
||||
|
||||
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
|
||||
params.require(:gang).permit :name,
|
||||
:about,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
class Gang < ApplicationRecord
|
||||
has_many :homies
|
||||
end
|
||||
has_many :homies, class_name: "Homie"
|
||||
has_many :money_moves, through: :homies
|
||||
has_many :works, through: :homies
|
||||
end
|
||||
|
||||
@@ -25,6 +25,17 @@ class MoneyMove < ApplicationRecord
|
||||
settle_record.save
|
||||
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
|
||||
private
|
||||
|
||||
@@ -65,5 +76,6 @@ class MoneyMove < ApplicationRecord
|
||||
description: new_desc
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,14 @@
|
||||
class Work < ApplicationRecord
|
||||
belongs_to :homie
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"proxy": "http://localhost:3001",
|
||||
"dependencies": {
|
||||
"axios": "^0.19.0",
|
||||
"js-file-download": "^0.4.12",
|
||||
"materialize-css": "^1.0.0",
|
||||
"react": "^16.8.6",
|
||||
"react-dom": "^16.8.6",
|
||||
|
||||
@@ -5,6 +5,7 @@ import {errorToast} from "../common/errorHelpers";
|
||||
import {withRouter} from 'react-router-dom';
|
||||
import {GANGS} from "../RouteNames";
|
||||
import M from 'materialize-css';
|
||||
import fileDownload from 'js-file-download';
|
||||
|
||||
const GangDetails = (props) => {
|
||||
const gang = props.gang;
|
||||
@@ -13,6 +14,17 @@ const GangDetails = (props) => {
|
||||
|
||||
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 updatedGang = {
|
||||
name: gangName
|
||||
@@ -47,8 +59,17 @@ const GangDetails = (props) => {
|
||||
Make it done
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<h1> Pack up </h1>
|
||||
<div>
|
||||
<p>
|
||||
<Button onClick={getBackup}> Pack up </Button>
|
||||
</p>
|
||||
<p>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default withRouter(GangDetails);
|
||||
export default withRouter(GangDetails);
|
||||
|
||||
@@ -59,4 +59,4 @@ const Gangs = (props) => {
|
||||
)
|
||||
}
|
||||
|
||||
export default withRouter(Gangs);
|
||||
export default withRouter(Gangs);
|
||||
|
||||
@@ -5555,6 +5555,11 @@ jest@24.7.1:
|
||||
import-local "^2.0.0"
|
||||
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:
|
||||
version "1.1.6"
|
||||
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
|
||||
end
|
||||
end
|
||||
get 'backup'
|
||||
end
|
||||
resources :work
|
||||
resources :chips, only: %i[index create destroy]
|
||||
|
||||
Reference in New Issue
Block a user