diff --git a/apps/dashboard/app/controllers/projects_controller.rb b/apps/dashboard/app/controllers/projects_controller.rb index e0add5aba8..b11c54cbcd 100644 --- a/apps/dashboard/app/controllers/projects_controller.rb +++ b/apps/dashboard/app/controllers/projects_controller.rb @@ -2,7 +2,6 @@ # The controller for project pages /dashboard/projects. class ProjectsController < ApplicationController - # GET /projects/:id def show project_id = show_project_params[:id] diff --git a/apps/dashboard/app/javascript/icon_picker.js b/apps/dashboard/app/javascript/icon_picker.js index 703c658ddc..ccca950888 100644 --- a/apps/dashboard/app/javascript/icon_picker.js +++ b/apps/dashboard/app/javascript/icon_picker.js @@ -34,7 +34,7 @@ function picked(event) { function updateIcon(icon) { $(`#${ICON_SHOW_ID}`).attr("class", `fas fa-${icon} fa-fw app-icon`); - $(`#${ICON_SELECT_ID}`).val(`fas://${icon}`); + $(`#${ICON_SELECT_ID}`).val(`${icon}`); } function populateList() { @@ -55,12 +55,8 @@ function addSearch(){ $(`#${ICON_SELECT_ID}`).on('input change', (event) => { const currentValue = event.target.value; - // template picked and set value or copy & pasted full icon uri - if(currentValue.startsWith('fas://')) { - updateIcon(currentValue.replace('fas://', '')); - } else { - searchIcons(event); - } + updateIcon(currentValue); + searchIcons(event); }); } diff --git a/apps/dashboard/app/models/concerns/icon_with_uri.rb b/apps/dashboard/app/models/concerns/icon_with_uri.rb new file mode 100644 index 0000000000..6631376ec4 --- /dev/null +++ b/apps/dashboard/app/models/concerns/icon_with_uri.rb @@ -0,0 +1,12 @@ +module IconWithUri + private + + def add_icon_uri + if @icon.nil? || @icon.empty? + @icon = 'fas://cog' + elsif @icon !~ /(fa[bsrl]?):\/\/(.*)/ + @icon = "fas://#{icon}" + end + @icon = @icon =~ /(fa[bsrl]?):\/\/(.*)/ || @icon.nil? || @icon.empty? ? @icon : "fas://#{@icon}" + end +end \ No newline at end of file diff --git a/apps/dashboard/app/models/product.rb b/apps/dashboard/app/models/product.rb index 0276c438eb..9ef7003ec3 100644 --- a/apps/dashboard/app/models/product.rb +++ b/apps/dashboard/app/models/product.rb @@ -3,6 +3,7 @@ # interact with. Products are what app developers interact with. class Product include ActiveModel::Model + include IconWithUri delegate :passenger_rack_app?, :passenger_rails_app?, :passenger_app?, :can_run_bundle_install?, to: :app @@ -163,6 +164,9 @@ def update(attributes) @description = attributes[:description] if attributes[:description] @icon = attributes[:icon] if attributes[:icon] @git_remote = attributes[:git_remote] if attributes[:git_remote] + + add_icon_uri + if self.valid? write_manifest set_git_remote diff --git a/apps/dashboard/app/models/project.rb b/apps/dashboard/app/models/project.rb index 5c60bf951e..0cf98fde7a 100644 --- a/apps/dashboard/app/models/project.rb +++ b/apps/dashboard/app/models/project.rb @@ -4,6 +4,8 @@ class Project include ActiveModel::Model include ActiveModel::Validations + include ActiveModel::Validations::Callbacks + include IconWithUri class << self def lookup_file @@ -74,6 +76,8 @@ def templates validate :project_directory_exist, on: [:create] validate :project_template_invalid, on: [:create] + before_validation :add_icon_uri + def initialize(attributes = {}) @id = attributes[:id] update_attrs(attributes) diff --git a/apps/dashboard/app/views/products/_form_icon.html.erb b/apps/dashboard/app/views/products/_form_icon.html.erb index 68c09d9058..2ea3ef651c 100644 --- a/apps/dashboard/app/views/products/_form_icon.html.erb +++ b/apps/dashboard/app/views/products/_form_icon.html.erb @@ -18,12 +18,12 @@ <%= fa_icon("cog", fa_style: "fas", id: "product_icon") %>

- There is no icon specified for this app. Default is fas://cog. + There is no icon specified for this app. Default is cog.
<% end %>
- <%= f.text_field :icon, placeholder: "fas://cog", id: "product_icon_select", - help: 'Use the list of icons below to choose from' %> + <%= f.text_field :icon, placeholder: "cog", id: "product_icon_select", + help: 'Use the list of icons below to choose from', value: product.app.manifest.icon.sub('fas://', '') %>
diff --git a/apps/dashboard/app/views/projects/_form.html.erb b/apps/dashboard/app/views/projects/_form.html.erb index 7ac3631fc4..3468dbe66d 100644 --- a/apps/dashboard/app/views/projects/_form.html.erb +++ b/apps/dashboard/app/views/projects/_form.html.erb @@ -58,7 +58,7 @@
<%= javascript_include_tag 'icon_picker', nonce: true %> - <%= form.text_field :icon, placeholder: "fas://cog", id: "product_icon_select" %> + <%= form.text_field :icon, placeholder: "cog", id: "product_icon_select", value: @project.icon_class %> <% if @project.icon =~ /(fa[bsrl]?):\/\/(.*)/ %> <% icon = $2; style = $1 %>

diff --git a/apps/dashboard/test/models/projects_test.rb b/apps/dashboard/test/models/projects_test.rb index 4510ea4c93..55cb10120c 100644 --- a/apps/dashboard/test/models/projects_test.rb +++ b/apps/dashboard/test/models/projects_test.rb @@ -23,12 +23,13 @@ class ProjectsTest < ActiveSupport::TestCase assert_not project.errors[:name].empty? invalid_directory = Project.dataroot - project = Project.new({ name: 'test', icon: 'invalid_format', directory: invalid_directory.to_s, + invalid_icon = 'invalid_format' + project = Project.new({ name: 'test', icon: invalid_icon, directory: invalid_directory.to_s, template: '/invalid/template' }) assert_not project.save - assert_equal 3, project.errors.size - assert_not project.errors[:icon].empty? + assert_equal 2, project.errors.size + assert_not_equal invalid_icon, project.icon assert_not project.errors[:directory].empty? assert_not project.errors[:template].empty? end @@ -218,9 +219,9 @@ class ProjectsTest < ActiveSupport::TestCase project = create_project(projects_path) assert_not project.update({ name: nil, icon: nil }) - assert_equal 2, project.errors.size + assert_equal 1, project.errors.size assert_not project.errors[:name].empty? - assert_not project.errors[:icon].empty? + assert_equal 'fas://cog', project.icon end end diff --git a/apps/dashboard/test/system/project_manager_test.rb b/apps/dashboard/test/system/project_manager_test.rb index 42e61cda4b..66c0c4b001 100644 --- a/apps/dashboard/test/system/project_manager_test.rb +++ b/apps/dashboard/test/system/project_manager_test.rb @@ -175,7 +175,7 @@ def add_auto_environment_variable(project_id, script_id, save: true) assert_equal 'my-test-project', find('#project_name').value assert_equal "#{dir}/projects/#{project_id}", find('#project_directory').value assert_equal 'test-description', find('#project_description').value - assert_equal 'fas://arrow-right', find('#product_icon_select').value + assert_equal 'arrow-right', find('#product_icon_select').value assert_selector '.btn.btn-default', text: 'Back' end end