Skip to content

Commit

Permalink
[webui] Add description editor for Kiwi packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Rolfe committed Oct 27, 2017
1 parent 28f59ee commit 14cee74
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 2 deletions.
44 changes: 44 additions & 0 deletions src/api/app/assets/javascripts/webui/application/kiwi_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ function enableSave(){
$('#kiwi-image-update-form-save, #kiwi-image-update-form-revert').addClass('enabled');
}

function editDescriptionDialog(){
var dialog = $('#kiwi-description').find('.dialog');
dialog.removeClass('hidden');
$('.overlay').show();
}

function editPackageDialog(){
var fields = $(this).parents('.nested-fields');
var dialog = fields.find('.dialog');
Expand Down Expand Up @@ -78,6 +84,39 @@ function addRepositoryErrorMessage(source_path, field) {
field.removeClass('hidden');
}

function closeDescriptionDialog() {
var fields = $(this).parents('.nested-fields');
var dialog = fields.find('.dialog');
var name = dialog.find("[id$='name']");

if (name.val() !== '') {
$('#image-name').text(name.val());
}
else {
fields.find(".ui-state-error").removeClass('hidden');
return false;
}

var elements = fields.find('.fill');
for(var i=0; i < elements.length; i++) {
var object = dialog.find("[id$='" + $(elements[i]).data('tag') + "']");
if ( object.val() != "") {
$(elements[i]).text(object.val());
}
}

addDefault(dialog);

if (!canSave) {
enableSave();
}

fields.find(".ui-state-error").addClass('hidden');

hideOverlay(dialog);
}


function closeDialog() {
var fields = $(this).parents('.nested-fields');
var is_repository = fields.parents('#kiwi-repositories-list').size() == 1;
Expand Down Expand Up @@ -136,6 +175,7 @@ function closeDialog() {
function revertDialog() {
var fields = $(this).parents('.nested-fields');
var dialog = fields.find('.dialog');
dialog.find(".ui-state-error").addClass('hidden');

if(dialog.hasClass('new_element')) {
hideOverlay(dialog);
Expand Down Expand Up @@ -297,6 +337,10 @@ $(document).ready(function(){
// Enable save button
$('.remove_fields').click(enableSave);

// Edit dialog for Description
$('.description_edit').click(editDescriptionDialog);
$('.close-description-dialog').click(closeDescriptionDialog);

// Edit dialog for Repositories and Packages
$('.repository_edit').click(editRepositoryDialog);
$('.package_edit').click(editPackageDialog);
Expand Down
11 changes: 11 additions & 0 deletions src/api/app/assets/stylesheets/webui/application/kiwi_image.scss
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,14 @@
margin-top: 3px;
}

#kiwi-description {
h2 { margin-bottom: 0;}

.inline {
li {
display: inline-block;

&:first-child { margin-left: 0; }
}
}
}
14 changes: 14 additions & 0 deletions src/api/app/controllers/webui/kiwi/images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def import_from_package
end

def show
@image.build_description if @image.description.nil? # Because the form needs a Description object instantiated
@package_groups = @image.default_package_group

respond_to do |format|
format.html
format.json { render json: { is_outdated: @image.outdated? } }
Expand Down Expand Up @@ -61,6 +63,14 @@ def autocomplete_binaries
private

def image_params
description_attributes = [
:id,
:author,
:contact,
:description_type,
:specification
]

repositories_attributes = [
:id,
:_destroy,
Expand All @@ -84,6 +94,10 @@ def image_params

params.require(:kiwi_image).permit(
:use_project_repositories,
:name,
:schema_version,
:displayname,
description_attributes: description_attributes,
repositories_attributes: repositories_attributes,
package_groups_attributes: package_groups_attributes
)
Expand Down
2 changes: 2 additions & 0 deletions src/api/app/models/kiwi/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Image < ApplicationRecord

#### Associations macros (Belongs to, Has one, Has many)
has_one :package, foreign_key: 'kiwi_image_id', class_name: '::Package', dependent: :nullify, inverse_of: :kiwi_image
has_one :description, inverse_of: :image, dependent: :destroy
has_many :repositories, -> { order(order: :asc) }, dependent: :destroy, index_errors: true
has_many :package_groups, -> { order(:id) }, dependent: :destroy, index_errors: true
has_many :kiwi_packages, -> { where(kiwi_package_groups: { kiwi_type: Kiwi::PackageGroup.kiwi_types[:image] }) },
Expand All @@ -31,6 +32,7 @@ class Image < ApplicationRecord
validates :name, presence: true
validate :check_use_project_repositories
validate :check_package_groups
accepts_nested_attributes_for :description
accepts_nested_attributes_for :repositories, allow_destroy: true
accepts_nested_attributes_for :package_groups, allow_destroy: true
accepts_nested_attributes_for :kiwi_packages, allow_destroy: true
Expand Down
44 changes: 44 additions & 0 deletions src/api/app/views/webui/kiwi/images/_description.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#kiwi-description
.nested-fields
%h2#image-name
= @image.name
%p
%span.fill{ data: { tag: 'specification' }}= @image.description.specification
%ul.inline
%li
%strong Author:
%span.fill{ data: { tag: 'author' }}= @image.description.author
%li
%strong Contact:
%span.fill{ data: { tag: 'contact' }}= @image.description.contact
%p
= link_to sprited_text('package_edit', 'Edit details'), '#', class: 'description_edit'

.dialog.darkgrey_box.hidden{ style: "width: 500px; left: 45%;" }
.box.box-shadow
%h2.box-header Edit Kiwi Details

.dialog-content
%p
= f.label :name
= f.text_field :name, data: { default: f.object.name }

%p
= f.fields_for :description, f.object.description do |description_fields|
%p
= description_fields.label :author
= description_fields.text_field :author, data: { default: description_fields.object.author }
%p
= description_fields.label :contact
= description_fields.text_field :contact, data: { default: description_fields.object.contact }
%p
= description_fields.label :specification
= description_fields.text_field :specification, data: { default: description_fields.object.specification }

%p#flash-messages
%p.ui-state-error.ui-widget-shadow.hidden
Kiwi Image name can not be empty!

.dialog-buttons
= link_to('Cancel', '#', title: 'Cancel', class: 'revert-dialog')
= link_to('Continue', '#', title: 'Continue', class: 'close-description-dialog')
4 changes: 2 additions & 2 deletions src/api/app/views/webui/kiwi/images/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
= form_for @image, html: { id: 'kiwi-image-update-form' } do |f|
.grid_16.alpha.omega.box.box-shadow
= render partial: 'webui/kiwi/tabs'
%h2
= @image.name

= render partial: 'webui/kiwi/images/description', locals: { f: f }

.grid_16.alpha.omega.box.box-shadow
= render partial: 'webui/kiwi/images/repositories', locals: { f: f }
Expand Down

0 comments on commit 14cee74

Please sign in to comment.