diff options
author | bill-auger <mr.j.spam.me@gmail.com> | 2020-03-21 16:04:20 -0400 |
---|---|---|
committer | bill-auger <mr.j.spam.me@gmail.com> | 2020-04-13 01:27:35 -0400 |
commit | be47c6579561197b8bfcb321167afa7a6ba00d8b (patch) | |
tree | 35c036af3b0a2137c9ded6f20de32f6915f9e707 | |
parent | 3b285612d04f37926a7dac7599617328e04c933c (diff) |
wip - display metadata
-rw-r--r-- | app/controllers/downloads_controller.rb | 59 | ||||
-rw-r--r-- | app/models/download.rb | 23 | ||||
-rw-r--r-- | app/views/downloads/index.html.erb | 4 | ||||
-rw-r--r-- | app/views/downloads/select.html.erb | 150 | ||||
-rw-r--r-- | app/views/layouts/download.html.erb | 2 | ||||
-rw-r--r-- | config/initializers/downloads_constants.rb | 16 |
6 files changed, 208 insertions, 46 deletions
diff --git a/app/controllers/downloads_controller.rb b/app/controllers/downloads_controller.rb index 9de41fdd8..48275991a 100644 --- a/app/controllers/downloads_controller.rb +++ b/app/controllers/downloads_controller.rb @@ -50,7 +50,9 @@ private # and each successive instance var will be nil, # because options may depend on the selections of preceding parameters # see also the note in the 'set_nojs_param' method + arch , init, wmde , install = IMAGE_PARAMS.map { | param | params[param.to_s] } + (@arch = arch if VALID_RELEASE_ARCHES .include? arch ) && (@init = init if VALID_RELEASE_INITS .include? init ) && (@wmde = wmde if VALID_RELEASE_WMDES .include? wmde ) && @@ -64,17 +66,25 @@ private # :wmde => @wmde , :install => @install } # @all_params_satisfied = @image_params.values.all? &:present? - @nojs = params['nojs' ].present? - @redirect_requested = params['download'].present? + @nojs = params['nojs' ] == 'true' + @redirect_requested = params['download'] == 'true' end def collect_images + @release_images_tree , @release_images = Download.collect_images RELEASES_DIR , RELEASES_GLOB , RELEASES_URL + @qemu_images_tree , @qemu_images = Download.collect_images RELEASES_DIR , QEMUS_GLOB , RELEASES_URL + @preview_images_tree , @preview_images = Download.collect_images PREVIEWS_DIR , PREVIEWS_GLOB , PREVIEWS_URL - @image_options , - @selectable_images = image_options - @selected_image = @selectable_images.first if @selectable_images.size == 1 +# @image_options , +# @selectable_images = image_options +# @selected_image = @selectable_images.first if @selectable_images.size == 1 + @image_options = image_options + @selected_image = @release_images_tree[@image_options[:arch ][:selected]] \ + [@image_options[:init ][:selected]] \ + [@image_options[:wmde ][:selected]] \ + [@image_options[:install][:selected]] @all_params_satisfied = ([ @arch , @init , @wmde , @install ].all? &:present?) # byebug end @@ -102,9 +112,11 @@ private def image_options image_options = IMAGE_OPTIONS.deep_dup - IMAGE_PARAMS.each { | param_id | set_nojs_param image_options , param_id } if @nojs - selectable_images = @release_images.select do | image_data | +# IMAGE_PARAMS.each { | param_id | set_nojs_params image_options , param_id } + set_nojs_params image_options if @nojs +=begin + selectable_images = @release_images_tree.select do | image_data | puts "#{image_data[:image_name]}" IMAGE_PARAMS.all? do | param_id | selected_option = image_options[param_id][:selected] @@ -112,7 +124,7 @@ puts " param_id=#{param_id} image_data=#{image_data[param_id.to_s]} selected_op image_data[param_id.to_s] == selected_option || selected_option.nil? end end -# +=end # selected_image = selectable_images.detect do | image_data | # IMAGE_PARAMS.all? do | param_id | # selected_option = image_options[param_id][:selected] @@ -122,31 +134,48 @@ puts " param_id=#{param_id} image_data=#{image_data[param_id.to_s]} selected_op # end # byebug if selected_image.nil? # [ image_options , selectable_images , selected_image ] - [ image_options , selectable_images ] +# [ image_options , selectable_images ] + image_options end - def set_nojs_param image_options , param_id + def set_nojs_params image_options # param_id = param_data [:param_id] # selected_value = @image_params[param_id ] - param_data = image_options[param_id] - selected_value = (eval "@#{param_id}") if IMAGE_PARAMS.include? param_id + selectable_images = @release_images_tree + + set_nojs_param image_options , IMAGE_PARAMS.deep_dup , selectable_images + end + + def set_nojs_param image_options , image_params , selectable_images + return unless image_params.present? # recursion base case +puts "set_nojs_param() image_params=#{image_params}" # NOTE: nojs # image parameters are accumulated as a "stack" of RESTful queries, # in the order of the parameters defiend in IMAGE_PARAMS + # the available options are constrained per the selections of preceding parameters # the first unset query parameter becomes the @nojs_current_param_id, # which indicates the currently visible option set to be presented - # the current selection of each successive parameter is then set to nil - # because options may depend on the selections of preceding parameters + # the default selection of each successive parameter is then set to nil, + # because the current selection will further constrain the options for the next # see also the note in the 'parse_params' method + param_id = image_params.shift + param_data = image_options[param_id] # dup? + selected_value = (eval "@#{param_id}") if IMAGE_PARAMS.include? param_id +puts "set_nojs_param() param_id=#{param_id}" + param_data[:options].each do | option | + option[:enabled] = selectable_images[option[:option_id]].present? + end + if @nojs_current_param_id.present? param_data[:selected] = nil elsif selected_value.present? param_data[:selected] = selected_value + selectable_images = selectable_images[selected_value] || {} else @nojs_current_param_id = param_id end - param_data + set_nojs_param image_options , image_params , selectable_images end end diff --git a/app/models/download.rb b/app/models/download.rb index a1789bb84..6cd884597 100644 --- a/app/models/download.rb +++ b/app/models/download.rb @@ -2,18 +2,25 @@ class Download < ActiveRecord::Base def self.collect_images base_dir , glob , base_url image_sigs = Dir.glob "#{base_dir}#{glob}" - images_data = image_sigs.map do | sig | + images_tree = IMAGES_TREE.deep_dup + images = [] + + image_sigs.each do | sig | image_rel_path = sig.gsub SIG_FILE_REGEX , '\1' local_abs_path = "#{base_dir}/#{image_rel_path}" image_url = "#{base_url}/#{image_rel_path}" release_dir = image_rel_path.gsub /\/[^\/]*/ , '' image_name = image_rel_path.gsub /.*\// , '' image_params = (image_name.match IMAGE_FILE_REGEX).named_captures - image_size = (File.size "#{local_abs_path}") if File.exist? local_abs_path - pkglist = "#{base_dir}/#{release_dir}/pkglist.#{image_params['arch']}.txt" + arch = image_params['arch' ] + init = image_params['init' ] + wmde = image_params['wmde' ] + install = image_params['install'] + image_size = "#{(File.size local_abs_path) / 1000000} MB" if File.exist? local_abs_path + pkglist = "#{base_dir}/#{release_dir}/pkglist.#{arch}.txt" kernel_ver = parse_kernel_version pkglist release_dir_url = "#{base_url}/#{release_dir}" - pkglist_url = "#{release_dir_url}/#{pkglist}" # FIXME: + pkglist_url = "#{release_dir_url}/#{pkglist}" magnet = "#{local_abs_path}.magnet" magnet_uri = (File.read magnet).trim if File.exist? magnet torrent_url = "#{image_url}.torrent" @@ -26,11 +33,15 @@ class Download < ActiveRecord::Base image_data_keys = [ :image_url , :image_name , :image_size , :kernel_ver , :pkglist_url , :magnet_uri , :torrent_url , :checksums_url , :signature_url , :gpg_key_url ] + image_data = image_data_keys.to_h { | key | ; [ key , (eval key.to_s) ] } # puts "image_params=#{image_params}" - image_data_keys.to_h { | key | ; [ key , (eval key.to_s) ] }.merge image_params + images_tree[arch][init][wmde][install] = image_data + images << image_data +# (((images_tree[arch] ||= {}) [init] ||= {}) [wmde] ||= {}) [install] = image_data end - (images_data.present?) ? images_data : [ {} ] +# (images_data.present?) ? images_data : [ {} ] + [ images_tree , images ] end def self.parse_kernel_version pkglist diff --git a/app/views/downloads/index.html.erb b/app/views/downloads/index.html.erb index d95a3980e..c0d252cb1 100644 --- a/app/views/downloads/index.html.erb +++ b/app/views/downloads/index.html.erb @@ -35,7 +35,7 @@ <tr> <% if image_url.present? && image_name.present? && image_size.present? %> <td class="releases-image-td"><a href="<%= image_url %>"><%= image_name %></a></td> - <td>(<%= image_size / 1000000 %> MB)</td> + <td>(<%= image_size %> )</td> <% else %> <td>none available</td> <% end %> @@ -47,6 +47,7 @@ <div id="releases-desc-div" class="releases-div"> <h2 class="releases-h2">Parabola GNU/Linux-libre Release Images and Installers</h2> + <table id="releases-desc-scrots-table"> <tr><td><a href="https://wiki.parabola.nu/images/4/4e/Parabola-systemd-2018-iso-boot-scrot.png"> <img src="https://wiki.parabola.nu/images/thumb/4/4e/Parabola-systemd-2018-iso-boot-scrot.png/400px-Parabola-systemd-2018-iso-boot-scrot.png" /></a></td> @@ -55,6 +56,7 @@ <td><a href="https://wiki.parabola.nu/images/6/61/Parabola-lxde-2020.png"> <img src="https://wiki.parabola.nu/images/5/5f/480px-parabola-lxde-2020.png" /></a></td></tr> </table> + <p>Just as with all software packages in the Parabola repositories, the Parabola GNU/Linux-libre release images are cryptographically signed by a member of the Parabola project. Check-sums are also provided to quickly verify that the downloaded file itself, is not corrupted; but the signature is most significant. Any of these files may be obtained from sources other than directly from the Parabola project or Parabola mirrors. Only a valid signature, confirms that the ISO file was received in the pristine state, as provided by the Parabola project.</p> <p>The signature can be verified by importing the "Signing Key", noted beside each release image. Verifying signatures is beyond the scope of this article; but the <a href="https://www.parabola.nu/people/hackers/">Parabola developers signing keys</a> are published on the Parabola website.</p> <p>It is strongly recommended that you keep a Parabola LiveISO ready to use at all times. It will save you much time and trouble, if ever the system becomes un-bootable, or otherwise needs repair.</p> diff --git a/app/views/downloads/select.html.erb b/app/views/downloads/select.html.erb index deb3705cc..7f5cb86ee 100644 --- a/app/views/downloads/select.html.erb +++ b/app/views/downloads/select.html.erb @@ -7,7 +7,7 @@ font-size: 13px ; text-decoration: none ; } #release-select-bwd-a , #release-select-fwd-button { background-color: #080 ; color: #FFF ; } - #release-select-metadata-span { display: block ; margin-top: 1em ; } + #release-select-metadata-div { margin-top: 1em ; } #release-select-inputs-table { padding: 0em 2em 0em 1em ; } #release-select-inputs-table , @@ -60,19 +60,19 @@ <% pkglist_url = @selected_image[:pkglist_url ] %> <% magnet_uri = @selected_image[:magnet_uri ] %> <% torrent_url = @selected_image[:torrent_url ] %> - <% checksums = @selected_image[:checksums_url] %> + <% checksums_url = @selected_image[:checksums_url] %> <% signature_url = @selected_image[:signature_url] %> <% gpg_key_url = @selected_image[:gpg_key_url ] %> - <span id="release-select-metadata-span"> - Kernel: <%= kernel_ver %><br /> - Size: <%= "#{image_size} MB" %><br /> - <a id="release-select-pkgs-a" href="<%= pkglist_url %>">Packages</a ><br /> - <a id="release-select-magnet-a" href="<%= magnet_uri %>">Magnet</a ><br /> - <a id="release-select-torrent-a" href="<%= torrent_url %>">Torrent</a ><br /> - <a id="release-select-sums-a" href="<%= checksums %>">SHA512SUMS</a ><br /> - <a id="release-select-sig-a" href="<%= signature_url %>">Signature</a ><br /> - <a id="release-select-gpg-a" href="<%= gpg_key_url %>">Signing Key</a><br /> - </span> + <div id="release-select-metadata-div"> + <span id="release-select-kernel-span">Kernel: <%= kernel_ver %></span><br /> + <span id="release-select-size-span" >Size: <%= image_size %></span><br /> + <span><a id="release-select-pkgs-a" href="<%= pkglist_url %>">Packages</a ></span><br /> + <span><a id="release-select-magnet-a" href="<%= magnet_uri %>">Magnet</a ></span><br /> + <span><a id="release-select-torrent-a" href="<%= torrent_url %>">Torrent</a ></span><br /> + <span><a id="release-select-sums-a" href="<%= checksums_url %>">SHA512SUMS</a ></span><br /> + <span><a id="release-select-sig-a" href="<%= signature_url %>">Signature</a ></span><br /> + <span><a id="release-select-gpg-a" href="<%= gpg_key_url %>">Signing Key</a></span> + </div> <% end %> @@ -93,12 +93,128 @@ <script type="text/javascript"> - var nojs_input = document.getElementById ('release-nojs-input' ) ; - var download_input = document.getElementById ('release-download-input' ) ; +window.onload = ()=> +{ +// const IMAGE_PARAMS = <%=raw IMAGE_PARAMS.to_json %> ; + const VALID_RELEASE_ARCHES = <%=raw VALID_RELEASE_ARCHES.to_json %> ; + const VALID_RELEASE_INITS = <%=raw VALID_RELEASE_INITS.to_json %> ; + const VALID_RELEASE_WMDES = <%=raw VALID_RELEASE_WMDES.to_json %> ; + const VALID_RELEASE_INSTALLS = <%=raw VALID_RELEASE_INSTALLS.to_json %> ; + const RELEASE_IMAGES_TREE = <%=raw @release_images_tree.to_json %> ; + + var select_form = document.getElementById ('release-select-form' ) ; var input_tables = document.getElementsByClassName('release-select-input-table') ; + var download_input = document.getElementById ('release-download-input' ) ; + var nojs_input = document.getElementById ('release-nojs-input' ) ; + var kernel_li = document.getElementById ('release-select-kernel-span') ; + var size_li = document.getElementById ('release-select-size-span' ) ; + var pkgs_a = document.getElementById ('release-select-pkgs-a' ) ; + var magnet_a = document.getElementById ('release-select-magnet-a' ) ; + var torrent_a = document.getElementById ('release-select-torrent-a' ) ; + var sums_a = document.getElementById ('release-select-sums-a' ) ; + var sig_a = document.getElementById ('release-select-sig-a' ) ; + var gpg_a = document.getElementById ('release-select-gpg-a' ) ; +// var radios = [ select_form.arch , select_form.init , +// select_form.wmde , select_form.install ] ; + var radios = { 'arch': {} , 'init': {} , 'wmde': {} , 'install': {} } ; + function SetRadio(param_id , option_id) + { + var radio_id = 'release-' + param_id + '-' + option_id + '-input' ; + var radio = document.getElementById(radio_id) ; + radios[param_id][option_id] = radio ; + radio.onclick = onClicked ; + } + VALID_RELEASE_ARCHES .forEach((arch )=> { SetRadio('arch' , arch ) ; }) ; + VALID_RELEASE_INITS .forEach((init )=> { SetRadio('init' , init ) ; }) ; + VALID_RELEASE_WMDES .forEach((wmde )=> { SetRadio('wmde' , wmde ) ; }) ; + VALID_RELEASE_INSTALLS.forEach((install)=> { SetRadio('install' , install) ; }) ; - nojs_input.parentNode.removeChild(nojs_input) ; - download_input.value = true ; +// for (var radio_n = 0 ; radio_n < radios.length ; ++radio_n) +// for (var input_n = 0 ; input_n < radios[radio_n].length ; ++input_n) +// radios[radio_n][input_n].onclick = onClicked ; +// radios.forEach((radio)=> { radio.onclick = onClicked ; }) ; +// radios[radio_n][input_n].onclick = ()=> { download_input.value = false ; select_form.submit() ; } ; for (var table_n = 0 ; table_n < input_tables.length ; ++table_n) - { input_tables[table_n].style.display = 'block' } + input_tables[table_n].style.display = 'block' ; + download_input.value = true ; + nojs_input.parentNode.removeChild(nojs_input) ; + + function onClicked(evt) + { +console.log("onclicked() this=" + this.name) ; + +// console.log("onclicked() RELEASE_IMAGES_TREE[" + Object.keys(RELEASE_IMAGES_TREE).length + "]=" + JSON.stringify(RELEASE_IMAGES_TREE)) ; +// console.log("onclicked() arch =" + select_form.arch .value) ; console.log("onclicked() init =" + select_form.init .value) ; console.log("onclicked() wmde =" + select_form.wmde .value) ; console.log("onclicked() install=" + select_form.install .value) ; +/* + image_data = RELEASE_IMAGES.find((image_data)=> + { +console.log("onclicked() image_data['arch' ]=" + image_data['arch']) ; console.log("onclicked() image_data['init' ]=" + image_data['init']) ; console.log("onclicked() image_data['wmde' ]=" + image_data['wmde']) ; console.log("onclicked() image_data['install']=" + image_data['install']) ; + + return image_data['arch' ] == select_form.arch .value && + image_data['init' ] == select_form.init .value && + image_data['wmde' ] == select_form.wmde .value && + image_data['install'] == select_form.install.value ; + }) ; +*/ + + var arch = select_form.arch .value ; + var init = select_form.init .value ; + var wmde = select_form.wmde .value ; + var install = select_form.install.value ; + var image_data = RELEASE_IMAGES_TREE[arch][init][wmde][install] ; + +// if (image_data !== undefined) + if (!!image_data) + { +console.log("onclicked() got image_data " + image_data['image_url' ]) ; +// console.log("onclicked() image_data=" + JSON.stringify(image_data)) ; + + kernel_li.textContent = "Kernel: " + image_data['kernel_ver' ] ; + size_li .textContent = "Size: " + image_data['image_size' ] ; + pkgs_a .href = image_data['pkglist_url' ] ; + magnet_a .href = image_data['magnet_uri' ] ; + torrent_a.href = image_data['torrent_url' ] ; + sums_a .href = image_data['checksums_url'] ; + sig_a .href = image_data['signature_url'] ; + gpg_a .href = image_data['gpg_key_url' ] ; + } + +// var rs = [ select_form.arch , select_form.init , select_form.wmde , select_form.install ] ; +// var param = this.name ; +// var param_n = IMAGE_PARAMS.indexOf(this.name) ; +// var param = IMAGE_PARAMS[param_n] ; +// var radio = rs[param_n] ; +// var image_tree = (param == 'arch' ) ? RELEASE_IMAGES_TREE : +// (param == 'init' ) ? RELEASE_IMAGES_TREE[arch] : +// (param == 'wmde' ) ? RELEASE_IMAGES_TREE[arch][init] : +// (param == 'install') ? RELEASE_IMAGES_TREE[arch][init][wmde] ; + + function enableRadios(arch , init , wmde , install) + { + var has_image = !!RELEASE_IMAGES_TREE[arch][init][wmde][install] ; + + if (has_image) + { + radios['arch'][arch].enabled = true ; radios['init' ][init ].enabled = true ; + radios['wmde'][wmde].enabled = true ; radios['install'][install].enabled = true ; + } + } + VALID_RELEASE_ARCHES .forEach((arch )=> { radios['arch' ][arch ].enabled = false ; + VALID_RELEASE_INITS .forEach((init )=> { radios['init' ][init ].enabled = false ; + VALID_RELEASE_WMDES .forEach((wmde )=> { radios['wmde' ][wmde ].enabled = false ; + VALID_RELEASE_INSTALLS.forEach((install)=> { radios['install'][install].enabled = false ; + enableRadios(arch , init , wmde , install) ; + }) ; }) ; }) ; }) ; + + +// VALID_RELEASE_INITS +// VALID_RELEASE_WMDES +// VALID_RELEASE_INSTALLS +"release-#{param_id}-#{option_id}-input" +// for (var radio_n = 0 ; radio_n < radios.length ; ++radio_n) +// for (var input_n = 0 ; input_n < radios[radio_n].length ; ++input_n) +// radio[input_n].enabled + + } +} </script> diff --git a/app/views/layouts/download.html.erb b/app/views/layouts/download.html.erb index 62beacd79..cac641f07 100644 --- a/app/views/layouts/download.html.erb +++ b/app/views/layouts/download.html.erb @@ -13,7 +13,7 @@ <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> <%= javascript_heads %> <%= heads_for_theme %> -<%= call_hook :view_layouts_base_html_head %> +<!-- < % = call_hook :view_layouts_base_html_head %> --> <%= yield :header_tags -%> </head> diff --git a/config/initializers/downloads_constants.rb b/config/initializers/downloads_constants.rb index 1edca0161..40c6c705b 100644 --- a/config/initializers/downloads_constants.rb +++ b/config/initializers/downloads_constants.rb @@ -42,8 +42,12 @@ VALID_RELEASE_ARCHES = [ ARCH_ARMV7H , ARCH_X8664 , ARCH_I686 VALID_RELEASE_INITS = [ INIT_OPENRC , INIT_SYSTEMD ] VALID_RELEASE_WMDES = [ WMDE_CLI , WMDE_LXDE , WMDE_TALKING ] VALID_RELEASE_INSTALLS = [ INSTALL_COMPLETE , INSTALL_NETINSTALL ] +INSTALLS_TREE = VALID_RELEASE_INSTALLS.to_h { | key | [ key , nil ] } +WMDES_TREE = VALID_RELEASE_WMDES .to_h { | key | [ key , INSTALLS_TREE ] } +INITS_TREE = VALID_RELEASE_INITS .to_h { | key | [ key , WMDES_TREE ] } +IMAGES_TREE = VALID_RELEASE_ARCHES .to_h { | key | [ key , INITS_TREE ] } -IMAGE_ARCH_OPTIONS = +IMAGE_ARCH_OPTIONS = { :prompt => ARCH_PROMPT , :selected => ARCH_X8664 , @@ -52,14 +56,14 @@ IMAGE_ARCH_OPTIONS = { :option_id => ARCH_I686 , :label => ARCH_I686 , :desc => I686_DESC } , { :option_id => ARCH_X8664 , :label => ARCH_X8664 , :desc => X8664_DESC } ] } -IMAGE_INIT_OPTIONS = +IMAGE_INIT_OPTIONS = { :prompt => INIT_PROMPT , :selected => INIT_SYSTEMD , :options => [ { :option_id => INIT_OPENRC , :label => OPENRC_LABEL , :desc => OPENRC_DESC } , { :option_id => INIT_SYSTEMD , :label => SYSTEMD_LABEL , :desc => SYSTEMD_DESC } ] } -IMAGE_WMDE_OPTIONS = +IMAGE_WMDE_OPTIONS = { :prompt => WMDE_PROMPT , :selected => WMDE_LXDE , @@ -67,15 +71,15 @@ IMAGE_WMDE_OPTIONS = { :option_id => WMDE_LXDE , :label => LXDE_LABEL , :desc => LXDE_DESC } , { :option_id => WMDE_TALKING , :label => TALKING_LABEL , :desc => TALKING_DESC } ] } -IMAGE_INSTALL_OPTIONS = +IMAGE_INSTALL_OPTIONS = { :prompt => INSTALL_PROMPT , :selected => INSTALL_NETINSTALL , :options => [ { :option_id => INSTALL_COMPLETE , :label => COMPLETE_LABEL , :desc => COMPLETE_DESC } , { :option_id => INSTALL_NETINSTALL , :label => NETINSTALL_LABEL , :desc => NETINSTALL_DESC } ] } -IMAGE_OPTIONS = { ARCH_KEY => IMAGE_ARCH_OPTIONS , INIT_KEY => IMAGE_INIT_OPTIONS , - WMDE_KEY => IMAGE_WMDE_OPTIONS , INSTALL_KEY => IMAGE_INSTALL_OPTIONS } +IMAGE_OPTIONS = { ARCH_KEY => IMAGE_ARCH_OPTIONS , INIT_KEY => IMAGE_INIT_OPTIONS , + WMDE_KEY => IMAGE_WMDE_OPTIONS , INSTALL_KEY => IMAGE_INSTALL_OPTIONS } MIRROR_DOTSRCORG = { :domain => 'dotsrc.org' , :isos_url => 'https://mirrors.dotsrc.org/parabola/iso' , |