Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/issue entry association #1297

Closed
wants to merge 14 commits into from
11 changes: 11 additions & 0 deletions app/assets/stylesheets/shared/_icons.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.fa-check {
color: $green;
}

.fa-info-circle {
color: $blue;
}

.fa-times {
color: $red;
}
17 changes: 3 additions & 14 deletions app/assets/stylesheets/shared/_validations.scss
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
.validation {
.fa-check {
color: $green;
}

.fa-info-circle {
color: $blue;
}

.fa-times {
color: $red;
}

&.validation-feed {
.validation-list {
list-style-type: none;
margin: 1rem 0 0;
padding: 0;

li {
i {
margin-right: .15rem;
margin-right: 0.15rem;
}

.text-error {
font-size: 90%;
margin: 0 0 .5rem 1.3rem;
margin: 0 0 0.5rem 1.6rem;
}

&:last-of-type .text-error {
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/tylium.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
@import 'shared/datatables';
@import 'shared/editor_toolbar';
@import 'shared/empty_state.scss';
@import 'shared/icons';
@import 'shared/inline_editable';
@import 'shared/mixins';
@import 'shared/noscript';
Expand Down
17 changes: 17 additions & 0 deletions app/assets/stylesheets/tylium/modules/_buttons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@
}
}

.btn-link {
background-color: transparent;
border: none;
color: $linkColor;
padding: 0;
text-decoration: none;

&:active,
&:focus,
&:hover,
&:not(:disabled):not(.disabled):active {
background-color: transparent;
box-shadow: none !important;
color: $linkColorHover;
}
}

.btn-placeholder {
align-items: center;
background-color: $primaryColor;
Expand Down
6 changes: 5 additions & 1 deletion app/assets/stylesheets/tylium/modules/_dots-menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

.dots-dropdown-header {
font-weight: 400 !important;

&:hover {
color: $linkColor !important;
background-color: initial !important;
Expand All @@ -21,6 +21,10 @@
margin-top: 0.3rem;
padding-top: 0.3rem;
}

&:not(:has(+ .dropdown-item)) {
display: none;
}
}

.dropdown-menu {
Expand Down
18 changes: 8 additions & 10 deletions app/assets/stylesheets/tylium/modules/_modals.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
.modal {

.modal-dialog {
max-width: 560px;
&:not(.modal-lg, .modal-xl) {
max-width: 560px;
}

.modal-content {
font-size: 0.9rem;

.modal-body {

.add_multiple_nodes_form {
display: none;

.add_multiple_nodes_error {
display: none;
color: #b94a48;
Expand Down Expand Up @@ -49,7 +49,6 @@
}

&#modal_delete_node {

ul {
list-style: disc;
padding-left: 30px;
Expand All @@ -70,7 +69,7 @@
text-decoration: underline !important;
}
}

.invalid-selection {
cursor: not-allowed;
}
Expand Down Expand Up @@ -109,13 +108,12 @@
}

&#try-pro {

.modal-dialog {
max-width: 80%;

.modal-body {
height: 80vh;

iframe {
border: none;
top: 0;
Expand All @@ -125,7 +123,7 @@
width: 100%;
}
}

.modal-header h5 span {
color: $primaryColor;
}
Expand Down
30 changes: 21 additions & 9 deletions app/models/concerns/has_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ def local_fields
# Extract a Title file if one exists.
def title
fields.fetch(
"Title",
"(No #[Title]# field)"
'Title',
'(No #[Title]# field)'
)
end

def title?
fields["Title"].present?
fields['Title'].present?
end

private

def update_container(container_field, updated_fields)
self.send(
:"#{container_field}=",
FieldParser.fields_hash_to_source(updated_fields)
)
end

module ClassMethods
Expand Down Expand Up @@ -52,14 +61,17 @@ def dradis_has_fields_for(container_field)
define_method :set_field do |field, value|
# Don't use 'fields' as a local variable name or it conflicts with the
# #fields getter method
updated_fields = fields
updated_fields = fields
updated_fields[field] = value
self.send(
:"#{container_field}=",
updated_fields.to_a.map { |h| "#[#{h[0]}]#\n#{h[1]}" }.join("\n\n")
)
self.update_container(container_field, updated_fields)
end

# Completely removes the field (field header and value) from the content
define_method :delete_field do |field|
updated_fields = fields
updated_fields.except!(field)
self.update_container(container_field, updated_fields)
end
end
end

end
45 changes: 28 additions & 17 deletions app/models/field_parser.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
class FieldParser
FIELDS_REGEX = /#\[(.+?)\]#[\r|\n](.*?)(?=#\[|\z)/m
FIELDLESS_REGEX = /^([\s\S]*?)(?=\n{,2}#\[.+?\]#|\z)/
HEADERLESS_REGEX = /^([\s\S]*?)(?=\n{,2}#\[.+?\]#|\z)/

# Convert serialized form data to Dradis-style item content.
def self.fields_to_source(serialized_form)
serialized_form.each_slice(2).map do |field_name, field_value|
field = field_name[:value]
value = field_value[:value]

str = ''
str << "#[#{field}]#\n" unless field.empty?
str << "#{value}" unless value.empty?
serialized_form.each_slice(2).map(&to_source).compact.join("\n\n")
end

str
end.compact.join("\n\n")
# Convert a hash of field name/value pairs to Dradis-style item content.
def self.fields_hash_to_source(fields)
fields.map(&to_source).compact.join("\n\n")
end

# Parse the contents of the field and split it to return a Hash of field
Expand All @@ -38,7 +34,7 @@ def self.source_to_fields(string)
# #[Description]#
# Lorem ipsum...
#
# If the string contains a fieldless string, it will be prepended to
# If the string contains a headerless field, it will be prepended to
# the result. E.g.
#
# Line 1
Expand All @@ -54,18 +50,33 @@ def self.source_to_fields_array(string)
field.map(&:strip)
end

fieldless_string = parse_fieldless_string(string)
headerless_fields = parse_fields_without_headers(string)

if fieldless_string.present?
array.prepend(['', fieldless_string])
if headerless_fields.present?
array.prepend(['', headerless_fields])
end

array
end

# Field-less strings are strings that do not have a field header (#[Field]#).
# Headerless fields are strings that do not have a field header (#[Field]#).
# This parses all characters before a field header or end of string.
def self.parse_fieldless_string(source)
source[FIELDLESS_REGEX, 1]
def self.parse_fields_without_headers(source)
source[HEADERLESS_REGEX, 1]
end

private

def self.to_source
return Proc.new do |field, value|
field = field.is_a?(String) ? field.to_s : field[:value]
value = value.is_a?(String) ? value.to_s : value[:value]

str = ''
str << "#[#{field}]#\n" unless field.empty?
str << value unless value.empty?

str
end
end
end
Loading
Loading