mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-04 12:14:37 +08:00
adds team space related methods
This commit is contained in:
parent
86c6ae3b03
commit
1fefeee3d1
4 changed files with 16 additions and 2 deletions
|
@ -3,7 +3,9 @@ class TinyMceAssetsController < ApplicationController
|
|||
|
||||
def create
|
||||
image = params.fetch(:file) { render_404 }
|
||||
tiny_img = TinyMceAsset.new(image: image, reference: @obj)
|
||||
tiny_img = TinyMceAsset.new(image: image,
|
||||
reference: @obj,
|
||||
team_id: current_team.id)
|
||||
if tiny_img.save
|
||||
render json: {
|
||||
image: {
|
||||
|
|
|
@ -103,7 +103,7 @@ module ApplicationHelper
|
|||
end
|
||||
|
||||
def smart_annotation_parser(text, team = nil)
|
||||
team = nil unless team.kind_of? Team
|
||||
team = nil unless team.is_a? Team
|
||||
new_text = smart_annotation_filter_resources(text)
|
||||
new_text = smart_annotation_filter_users(new_text, team)
|
||||
new_text
|
||||
|
|
|
@ -2,6 +2,7 @@ class TinyMceAsset < ActiveRecord::Base
|
|||
attr_accessor :reference
|
||||
before_create :set_reference
|
||||
after_create :update_estimated_size
|
||||
after_destroy :release_team_space
|
||||
|
||||
belongs_to :step, inverse_of: :tiny_mce_assets
|
||||
belongs_to :result_text, inverse_of: :tiny_mce_assets
|
||||
|
@ -56,9 +57,19 @@ class TinyMceAsset < ActiveRecord::Base
|
|||
|
||||
def update_estimated_size
|
||||
return if image_file_size.blank?
|
||||
team = Team.find_by_id(team_id)
|
||||
es = image_file_size * Constants::ASSET_ESTIMATED_SIZE_FACTOR
|
||||
update(estimated_size: es)
|
||||
Rails.logger.info "Asset #{id}: Estimated size successfully calculated"
|
||||
# update team space taken
|
||||
team.take_space(es)
|
||||
team.save
|
||||
end
|
||||
|
||||
def release_team_space
|
||||
team = Team.find_by_id(team_id)
|
||||
team.release_space(estimated_size)
|
||||
team.save
|
||||
end
|
||||
|
||||
def set_reference
|
||||
|
|
|
@ -4,6 +4,7 @@ class AddAttachmentImageToTinyMceAssets < ActiveRecord::Migration
|
|||
t.attachment :image
|
||||
t.integer :estimated_size, default: 0, null: false
|
||||
t.references :step, index: true
|
||||
t.references :team, index: true
|
||||
t.references :result_text, index: true
|
||||
t.timestamps null: false
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue