Skip to content

Commit

Permalink
Merge pull request #3020 from bitzesty/staging
Browse files Browse the repository at this point in the history
Production < staging
  • Loading branch information
TheDancingClown authored Jul 31, 2024
2 parents 5fd3e10 + c65cfc7 commit cae4f41
Show file tree
Hide file tree
Showing 64 changed files with 399 additions and 410 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (C) 2014 Crown Copyright (Department for Business, Energy & Industrial Strategy) & Bit Zesty
Copyright (C) 2014 Crown Copyright (Department for Business and Trade) & Bit Zesty

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
93 changes: 0 additions & 93 deletions app/assets/javascripts/ckeditor/plugins/wordcount/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,52 +293,6 @@ CKEDITOR.plugins.add("wordcount", {
return true;
}

//If the limit is already over, allow the deletion of characters/words. Otherwise,
//the user would have to delete at one go the number of offending characters
var deltaWord = wordCount - lastWordCount;
var deltaChar = charCount - lastCharCount;

lastWordCount = wordCount;
lastCharCount = charCount;

if (lastWordCount == -1) {
lastWordCount = wordCount;
}
if (lastCharCount == -1) {
lastCharCount = charCount;
}

// Check for word limit and/or char limit
if ((config.maxWordCount > -1 && wordCount > maxWordCountWithBuffer(config.maxWordCount) && deltaWord > 0) ||
(config.maxCharCount > -1 && charCount > config.maxCharCount && deltaChar > 0)) {

limitReached(editorInstance, limitReachedNotified);
} else if ((config.maxWordCount == -1 || wordCount <= maxWordCountWithBuffer(config.maxWordCount)) &&
(config.maxCharCount == -1 || charCount <= config.maxCharCount)) {

limitRestored(editorInstance);
} else {
snapShot = editorInstance.getSnapshot();
}

// Fire Custom Events
if (config.charCountGreaterThanMaxLengthEvent && config.charCountLessThanMaxLengthEvent) {
if (charCount > config.maxCharCount && config.maxCharCount > -1) {
config.charCountGreaterThanMaxLengthEvent(charCount, config.maxCharCount);
} else {
config.charCountLessThanMaxLengthEvent(charCount, config.maxCharCount);
}
}

if (config.wordCountGreaterThanMaxLengthEvent && config.wordCountLessThanMaxLengthEvent) {
if (wordCount > maxWordCountWithBuffer(config.maxWordCount) && config.maxWordCount > -1) {
config.wordCountGreaterThanMaxLengthEvent(wordCount, config.maxWordCount);

} else {
config.wordCountLessThanMaxLengthEvent(wordCount, config.maxWordCount);
}
}

return true;
}

Expand Down Expand Up @@ -381,53 +335,6 @@ CKEDITOR.plugins.add("wordcount", {
updateCounter(event.editor);
}, editor, null, 100);

editor.on("paste", function(event) {
if (config.maxWordCount > 0 || config.maxCharCount > 0) {

// Check if pasted content is above the limits
var wordCount = -1,
charCount = -1,
text = event.editor.getData() + event.data.dataValue;


if (config.showCharCount) {
charCount = countCharacters(text, event.editor);
}

if (config.showWordCount) {
wordCount = countWords(text);
}


// Instantiate the notification when needed and only have one instance
if(notification === null) {
notification = new CKEDITOR.plugins.notification(event.editor, {
message: event.editor.lang.wordcount.pasteWarning,
type: 'warning',
duration: config.pasteWarningDuration
});
}

if (config.maxCharCount > 0 && charCount > config.maxCharCount && config.hardLimit) {
if(!notification.isVisible()) {
notification.show();
}
event.cancel();
}

if (config.maxWordCount > 0 && wordCount > maxWordCountWithBuffer(config.maxWordCount) && config.hardLimit) {
if(!notification.isVisible()) {
notification.show();
}
event.cancel();
}
}
}, editor, null, 100);

editor.on("afterPaste", function (event) {
updateCounter(event.editor);
}, editor, null, 100);

editor.on("blur", function () {
if (intervalId) {
window.clearInterval(intervalId);
Expand Down
30 changes: 25 additions & 5 deletions app/assets/javascripts/frontend/form-validation.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,31 @@ window.FormValidation =
return question.find("input[type='checkbox']").filter(":checked").length

validateWordLimit: (question) ->
wordLimit = $(question.context).attr("data-word-max")
wordCount = $(question.context).val().split(" ").length
if wordCount > wordLimit
@logThis(question, "validateWordLimit", "Word limit exceeded")
@addErrorMessage(question, "Exceeded #{wordLimit} word limit.")
questionRef = question.attr("data-question_ref")
textarea = question.find("textarea")
wordLimit = textarea.attr("data-word-max")
wordLimitWithBuffer = 0
if wordLimit > 15
wordLimitWithBuffer = parseInt(wordLimit * 1.1);
else
wordLimitWithBuffer = wordLimit;

editorInstance = CKEDITOR.instances[textarea.attr("id")]
if editorInstance?
editorContent = editorInstance.getData()
normalizedContent = editorContent
.replace(/<[^>]*>/g, ' ') # Remove HTML tags
.replace(/&nbsp;/g, ' ') # Replace non-breaking spaces
.replace(/\s+/g, ' ') # Replace multiple spaces with single space
.trim()
wordCount = normalizedContent.split(' ').length

if wordCount > wordLimitWithBuffer
@logThis(question, "validateWordLimit", "Word limit of #{wordLimit} exceeded. Word count at #{wordCount}.")
if wordLimit > 15
@addErrorMessage(question, "Question #{questionRef} has a word limit of #{wordLimit}. Your answer has to be #{wordLimitWithBuffer} words or less (as we allow 10% leeway).")
else
@addErrorMessage(question, "Question #{questionRef} has a word limit of #{wordLimit}. Your answer has to be #{wordLimitWithBuffer} words or less.")

validateSubfieldWordLimit: (question) ->
wordLimit = $(question.context).attr("data-word-max")
Expand Down
25 changes: 25 additions & 0 deletions app/assets/javascripts/frontend/vat_returns_upload.js.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
window.VatReturnsUpload =
init: ->
list = $('.vat-returns-wrapper .js-uploaded-list')
parent = list.closest('div.js-upload-wrapper')
max = parent.data('max-attachments')
govuk_button = $('.upload-file-btn')

updateUploadListVisiblity(list, govuk_button, max)

$('.js-vat-returns-upload').each (idx, el) ->
VatReturnsUpload.fileupload_init(el)

Expand All @@ -14,8 +21,10 @@ window.VatReturnsUpload =
$el = $(el)

parent = $el.closest('div.js-upload-wrapper')
max = parent.data('max-attachments')
list = parent.find('.js-uploaded-list')
form = parent.find('form.vat-returns-upload-form')
govuk_button = $('.upload-file-btn')

progress_all = (e, data) ->
# TODO
Expand Down Expand Up @@ -60,6 +69,8 @@ window.VatReturnsUpload =
list.find(".li-figures-upload").removeClass("govuk-!-display-none")
$(".js-vat-returns-status-message").remove()

updateUploadListVisiblity(list, govuk_button, max)

failed = (error_message) ->
parent.find(".govuk-error-message").html(error_message)
list.addClass("govuk-!-display-none")
Expand Down Expand Up @@ -91,3 +102,17 @@ window.VatReturnsUpload =
send: upload_started
always: success_or_error
)

updateUploadListVisiblity = (list, button, max) ->
list_elements = list.find("li").not('.dummy')
count = list_elements.length
wrapper = button.closest('div.js-upload-wrapper')

if count > 0
list.removeClass("hide")

if !max || count < max
button.removeClass("hide")

else
button.addClass("hide")
4 changes: 4 additions & 0 deletions app/decorators/form_answer_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ def website_url
document["website_url"]
end

def social_media_links
document["social_media_links"]
end

def head_of_business_title
document["head_of_business_title"] || document["head__of_bussines_title"]
end
Expand Down
16 changes: 10 additions & 6 deletions app/decorators/user_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ def role
end

def role_name
case object.role.to_s.humanize
when "Account admin"
"Admin and collaborator"
when "Regular"
"Collaborator only"
if account.owner == self
"Account owner"
else
object.role.to_s.humanize
case role.to_s.humanize
when "Account admin"
"Admin and collaborator"
when "Regular"
"Collaborator only"
else
role.to_s.humanize
end
end
end

Expand Down
2 changes: 2 additions & 0 deletions app/models/reports/admin_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def csv_filename
"#{category}_award#{sub_type}_#{id}_#{time}.csv"
when "reception-buckingham-palace"
"royal-reception-guest-list.csv"
when "registered-users"
"users-of-started-applications.csv"
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/reports/case_index_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def scoped_collection
scope = @year.form_answers
.shortlisted
.where(award_type: @category)
.order(:sic_code)
.order(Arel.sql("form_answers.document #>> '{sic_code}', form_answers.company_or_nominee_name"))

if @category == "trade"
years_mode_query = (@years_mode.to_s == "3") ? "3 to 5" : "6 plus"
Expand Down
4 changes: 2 additions & 2 deletions app/models/reports/form_answer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ def ac_received
if po_sd_provided_actual_figures?
"N/A - provided actual figures"
else
bool obj.audit_certificate.present?
bool(obj.audit_certificate.present? || obj.shortlisted_documents_submitted?)
end
end

def ac_checked
if po_sd_provided_actual_figures?
"N/A"
else
bool obj.audit_certificate.try(:reviewed?)
bool(obj.audit_certificate.try(:reviewed?) || obj.shortlisted_documents_wrapper&.reviewed?)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/pdf_generators/case_summary_pdfs/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def set_form_answers
.group("form_answers.id")
.having("count(assessor_assignments) > 0")
.where("assessor_assignments.submitted_at IS NOT NULL AND assessor_assignments.position IN (3,4)")
.order(Arel.sql("form_answers.award_year_id, form_answers.document #>> '{sic_code}'"))
.order(Arel.sql("form_answers.award_year_id, form_answers.document #>> '{sic_code}', form_answers.company_or_nominee_name"))
.group("form_answers.id")
.where("form_answers.award_year_id =?", award_year.id)

Expand Down
11 changes: 11 additions & 0 deletions app/pdf_generators/case_summary_pdfs/general/data_pointer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module CaseSummaryPdfs::General::DataPointer
AVERAGE_COLOR = "DAA520"
NEGATIVE_COLOR = "FF0000"
NEUTRAL_COLOR = "ECECEC"
LINK_REGEXP = /((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.-]+[.][a-z]{2,4}\/)(?:[^\s()<>`!{}:;'"\[\]]*))/im

def undefined_value
FeedbackPdfs::Pointer::UNDEFINED_VALUE
Expand Down Expand Up @@ -55,6 +56,16 @@ def current_awards
end
end

def website_url
matches = LINK_REGEXP.match(form_answer.decorate.website_url)
matches ? matches[0] : ""
end

def social_media_links
text = form_answer.decorate.social_media_links
text ? text.scan(LINK_REGEXP).flatten.map { |v| v.sub(/^https?:\/\/(www.)?/, "") } : []
end

def case_summaries_table_headers
[
[
Expand Down
Loading

0 comments on commit cae4f41

Please sign in to comment.