From 9afef8904bf295183654b0d36ae67c2c17d99bc1 Mon Sep 17 00:00:00 2001 From: Wedge Date: Wed, 22 Jan 2020 14:50:51 +0300 Subject: [PATCH] Add size --- app/helpers/application_helper.rb | 16 ++++++++++++++++ .../projects/build_lists/_packages.html.slim | 3 +++ .../projects/build_lists/show.json.jbuilder | 5 +++++ config/locales/models/build_list.en.yml | 1 + config/locales/models/build_list.ru.yml | 1 + ...0121215842_add_size_to_build_list_packages.rb | 5 +++++ db/schema.rb | 3 ++- 7 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20200121215842_add_size_to_build_list_packages.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e71065c61..fd709b416 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -101,4 +101,20 @@ module ApplicationHelper "alert-#{type}" end end + + def bytes_to_size(bytes) + sizes = [0, 1024, 1024*1024, 1024*1024*1024] + names = ['B', 'KiB', 'MiB', 'GiB'] + sizes.each_with_index do |l, i| + low, high = sizes[i], sizes[i+1] + if bytes >= low && (!high || bytes < high) + if low == 0 + sz = bytes + else + sz = (bytes.to_f / low).round(2) + end + return "#{sz}#{names[i]}" + end + end + end end diff --git a/app/views/projects/build_lists/_packages.html.slim b/app/views/projects/build_lists/_packages.html.slim index f6f198ed0..4e17729be 100644 --- a/app/views/projects/build_lists/_packages.html.slim +++ b/app/views/projects/build_lists/_packages.html.slim @@ -7,6 +7,7 @@ rd-widget ng-show='build_list.packages' th th= t('activerecord.attributes.build_list/package.fullname') th= t('activerecord.attributes.build_list/package.name') + th= t('activerecord.attributes.build_list/package.size') th= t('activerecord.attributes.build_list/package.epoch') th= t('activerecord.attributes.build_list/package.version') th= t('activerecord.attributes.build_list/package.release') @@ -27,6 +28,8 @@ rd-widget ng-show='build_list.packages' | {{::package.fullname}} td | {{::package.name}} + td + | {{::package.size}} td | {{::package.epoch}} td diff --git a/app/views/projects/build_lists/show.json.jbuilder b/app/views/projects/build_lists/show.json.jbuilder index 3c64c1eb2..eacd1475c 100644 --- a/app/views/projects/build_lists/show.json.jbuilder +++ b/app/views/projects/build_lists/show.json.jbuilder @@ -49,6 +49,11 @@ json.build_list do json.packages @build_list.packages do |package| json.(package, :id, :name, :fullname, :release, :version, :sha1, :epoch) json.url "#{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{package.sha1}" if package.sha1 + if package.size == 0 + json.size 'N/A' + else + json.size bytes_to_size(package.size) + end if @build_list.save_to_platform.main? json.dependent_projects dependent_projects(package) do |project, packages| diff --git a/config/locales/models/build_list.en.yml b/config/locales/models/build_list.en.yml index c387b756d..4a5bcd5b1 100644 --- a/config/locales/models/build_list.en.yml +++ b/config/locales/models/build_list.en.yml @@ -64,6 +64,7 @@ en: build_list/package: name: Name fullname: Fullname + size: Size epoch: Epoch release: Release version: Version diff --git a/config/locales/models/build_list.ru.yml b/config/locales/models/build_list.ru.yml index 59a3ee89d..c671e90f0 100644 --- a/config/locales/models/build_list.ru.yml +++ b/config/locales/models/build_list.ru.yml @@ -63,6 +63,7 @@ ru: build_list/package: name: Название fullname: Полное имя + size: Размер epoch: Эпоха release: Релиз version: Версия diff --git a/db/migrate/20200121215842_add_size_to_build_list_packages.rb b/db/migrate/20200121215842_add_size_to_build_list_packages.rb new file mode 100644 index 000000000..4d4ff469f --- /dev/null +++ b/db/migrate/20200121215842_add_size_to_build_list_packages.rb @@ -0,0 +1,5 @@ +class AddSizeToBuildListPackages < ActiveRecord::Migration + def change + add_column :build_list_packages, :size, :bigint, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 2bbcedd53..ef0216dd3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20190210143409) do +ActiveRecord::Schema.define(version: 20200121215842) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -56,6 +56,7 @@ ActiveRecord::Schema.define(version: 20190210143409) do t.string "sha1" t.integer "epoch" t.text "dependent_packages" + t.integer "size", :limit=>8, :default=>0 t.index :name=>"build_list_packages_ordering", :expression=>"lower((name)::text), length((name)::text)" end