Skip to content

Commit

Permalink
Merge pull request #2060 from brave-intl/staging
Browse files Browse the repository at this point in the history
Release 2019-07-18
  • Loading branch information
Cory McDonald authored Jul 19, 2019
2 parents 182fb5f + 24b5f1b commit ea8132c
Show file tree
Hide file tree
Showing 19 changed files with 432 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ gem "premailer-rails", "~> 1.9.4", require: false
gem 'public_suffix', '~> 3.0.2'

# Puma as app server
gem "puma", "3.12.1"
gem "puma", "~> 4.0.1"

# Make cracking a little bit harder
gem "rack-attack", "~> 5.0"
Expand Down
9 changes: 5 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ GEM
mime-types-data (~> 3.2015)
mime-types-data (3.2019.0331)
mimemagic (0.3.3)
mini_magick (4.9.3)
mini_magick (4.9.4)
mini_mime (1.0.1)
mini_portile2 (2.4.0)
minitest (5.11.3)
Expand All @@ -256,7 +256,7 @@ GEM
mustermann (1.0.3)
netrc (0.11.0)
newrelic_rpm (3.18.1.330)
nio4r (2.3.1)
nio4r (2.4.0)
nokogiri (1.10.3)
mini_portile2 (~> 2.4.0)
oauth (0.5.4)
Expand Down Expand Up @@ -319,7 +319,8 @@ GEM
binding_of_caller (>= 0.7)
pry (>= 0.9.11)
public_suffix (3.0.3)
puma (3.12.1)
puma (4.0.1)
nio4r (~> 2.0)
raabro (1.1.6)
rack (2.0.7)
rack-attack (5.4.2)
Expand Down Expand Up @@ -568,7 +569,7 @@ DEPENDENCIES
pry-byebug
pry-stack_explorer (~> 0.4.9.3)
public_suffix (~> 3.0.2)
puma (= 3.12.1)
puma (~> 4.0.1)
rack-attack (~> 5.0)
rails (~> 5.2.3)
rails-controller-testing
Expand Down
67 changes: 67 additions & 0 deletions app/assets/stylesheets/admin/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,70 @@ a.logo span {
left: 35px;
position: absolute;
}

.checkbox_1 {
height: 70px;
display: inline-flex;
align-items: center;
opacity: 0.9;
cursor: pointer;
position: relative;
}

.checkbox_1 > input {
width: 21px;
height: 21px;

appearance: none;

/* custom styling */
background-color: #fff;
border: 2px solid $braveGray-8;
border-radius: 5px;
cursor: pointer;
outline: none;

transition-duration: 0.1s;
}

.checkbox_1 > input:checked {
border: 3px solid #4c54d2;
background-color: #f3f3f6;
}

/* style checkmark symbol */
.checkbox_1 > input:checked + span::before {
color: #343546;
content: "\2713";

text-align: center;

display: block;
position: absolute;
left: 16px;
top: 22px;
}

.checkbox_1 > input:active {
border: 2px solid #7e47a8;
}

.checkbox_1 > input:focus + label::before {
outline: #fb542b solid 1px;
box-shadow: 0 0px 8px #7e47a8;
}

.reply:hover {
background: $braveBrand-Light;
cursor: pointer;
* {
color: $braveGray-10 !important;
}
}

#replySection {
left: 300px;
top: 0;
position: absolute;
z-index: 999999999;
}
4 changes: 3 additions & 1 deletion app/controllers/admin/case_notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ def create
end

def update
CaseNote.find(params[:id]).update(public: false)
note = CaseNote.find(params[:id])
note.update(public: false)
redirect_to admin_case_path(note.case)
end

private
Expand Down
38 changes: 38 additions & 0 deletions app/controllers/admin/case_replies_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module Admin
class CaseRepliesController < AdminController
def index
@open_cases = Case.where(status: Case::OPEN)
@assigned_cases = Case.where(assignee: current_user, status: Case::IN_PROGRESS)

@replies = CaseReply.all
end

def create
CaseReply.create(reply_params)
redirect_to admin_case_replies_path, flash: { notice: "Your saved reply was created successfully."}
end

def edit
@reply = CaseReply.find(params[:id])
@open_cases = Case.where(status: Case::OPEN)
@assigned_cases = Case.where(assignee: current_user, status: Case::IN_PROGRESS)
end

def update
CaseReply.find(params[:id]).update(reply_params)
redirect_to admin_case_replies_path, flash: { notice: "Your saved reply was updated successfully."}
end

def destroy
CaseReply.find(params[:id]).destroy
redirect_to admin_case_replies_path, flash: { notice: "Deleted the reply"}
end


private

def reply_params
params.require(:case_reply).permit(:id, :title, :body)
end
end
end
2 changes: 2 additions & 0 deletions app/controllers/admin/cases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def show

last_note = @notes.where(public: true).first
@answered = last_note&.created_by&.admin?

@replies = CaseReply.all
end

def assign
Expand Down
90 changes: 90 additions & 0 deletions app/javascript/packs/admin_case.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,65 @@
import Rails from "rails-ujs";

const shiftClick = () => {
// get array of items
var list = document.querySelector(".dynamic-table");
var items = list.querySelectorAll(".gradeX");

// create vars for tracking clicked items
var firstItem, lastItem;

// method for ticking all items between first and last
function tick(first, last) {
// items is a nodeList, so we do some prototype trickery
Array.prototype.forEach.call(items, function(el, i) {
// find each checkbox
var checkbox = el.getElementsByTagName("input")[0];
// tick all within first to last range
if ((i >= first && i <= last) || (i <= first && i >= last)) {
checkbox.checked = true;
}
});
}

// method for unticking all items except current item
function untickAllExcept(first) {
Array.prototype.forEach.call(items, function(el, i) {
var cb = el.querySelectorAll("input[type='checkbox']");
if (i !== first) {
cb[0].checked = false;
}
});
}

// click listener on list
list.addEventListener("click", function(e) {
if (e.target.type === "checkbox" || e.target.nodeName === "SPAN") {
var item = e.target.parentNode.parentNode;
if (e.target.nodeName === "SPAN") {
const checked = e.target.parentNode.firstChild.checked;
e.target.parentNode.firstChild.checked = !checked;
}

if (e.shiftKey) {
// store as last item clicked
lastItem = Array.prototype.indexOf.call(items, item);
} else {
// store as first item clicked
firstItem = Array.prototype.indexOf.call(items, item);
// unset last item
lastItem = null;
}

// do magic
if (lastItem != null) {
tick(firstItem, lastItem);
} else {
untickAllExcept(firstItem);
}
}
});
};

function selected(e) {
console.log(
"Original event that triggered text replacement:",
Expand All @@ -23,6 +83,8 @@ function selected(e) {
e.detail.item.original.key
}</div>`;

assignCheckboxes(e, event.target, assignedHTML);

const parent = event.target.closest("div");
if (parent.id) {
parent.classList.toggle("w-100");
Expand All @@ -39,6 +101,32 @@ function selected(e) {
}
}

function assignCheckboxes(e, target, assignedHTML) {
const checkbox = target
.closest("tr")
.querySelectorAll("input[type='checkbox']");

if (checkbox && checkbox[0].checked) {
const inputChecked = target
.closest("table")
.querySelectorAll("input[type='checkbox']:checked");

inputChecked.forEach(checked => {
const checkedForm = checked.closest("tr").querySelector("form");

checkedForm.querySelector(".assignee-input").value =
e.detail.item.original.value;
Rails.fire(checkedForm, "submit");

let parentDiv = checkedForm.closest("div");
if (parentDiv.id) {
parentDiv.classList.toggle("w-100");
parentDiv.closest("td").innerHTML = assignedHTML;
}
});
}
}

function toggleForm(event) {
const form = event.target.parentElement.parentElement.querySelector("form");
form.classList.toggle("d-none");
Expand All @@ -58,6 +146,8 @@ document.addEventListener("DOMContentLoaded", function() {
};
}

shiftClick();

document
.querySelectorAll(".filter")
.forEach(element => element.addEventListener("click", toggleForm));
Expand Down
Loading

0 comments on commit ea8132c

Please sign in to comment.