Fixes #2647 - Enhance CTI-Caller-Log to "mark as seen" all unread entries at once
This commit is contained in:
parent
ebe053efca
commit
08a98efca4
6 changed files with 83 additions and 8 deletions
|
@ -5,8 +5,9 @@ class App.CTI extends App.Controller
|
|||
elements:
|
||||
'.js-callerLog': 'callerLog'
|
||||
events:
|
||||
'click .js-check': 'done'
|
||||
'click .js-newUser': 'newUser'
|
||||
'click .js-check': 'done'
|
||||
'click .js-checkAll': 'doneAll'
|
||||
'click .js-newUser': 'newUser'
|
||||
list: []
|
||||
backends: []
|
||||
meta:
|
||||
|
@ -191,10 +192,23 @@ class App.CTI extends App.Controller
|
|||
|
||||
@updateNavMenu()
|
||||
|
||||
doneAll: =>
|
||||
|
||||
# get id's of all unchecked caller logs
|
||||
@logIds = $('.js-callerLog').map(->
|
||||
return $(@).data('id') if !$(@).find('.js-check').prop('checked')
|
||||
).get()
|
||||
|
||||
@ajax(
|
||||
type: 'POST'
|
||||
url: "#{@apiPath}/cti/done/bulk"
|
||||
data: JSON.stringify({ids: @logIds})
|
||||
)
|
||||
|
||||
done: (e) =>
|
||||
element = $(e.currentTarget)
|
||||
id = element.closest('tr').data('id')
|
||||
done = element.prop('checked')
|
||||
id = element.closest('tr').data('id')
|
||||
done = element.prop('checked')
|
||||
@ajax(
|
||||
type: 'POST'
|
||||
url: "#{@apiPath}/cti/done/#{id}"
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
<table class="table table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 40px;"></th>
|
||||
<th style="width: 40px;">
|
||||
<label class="checkbox-replacement checkbox-replacement--fullscreen">
|
||||
<input type="checkbox" class="js-checkAll">
|
||||
<%- @Icon('checkbox', 'icon-unchecked') %>
|
||||
<%- @Icon('checkbox-checked', 'icon-checked') %>
|
||||
</label>
|
||||
</th>
|
||||
<th><%- @T('From') %></th>
|
||||
<th><%- @T('To') %></th>
|
||||
<!--<th style="width: 100px;"><%- @T('Queue') %></th>-->
|
||||
|
@ -13,7 +19,7 @@
|
|||
</thead>
|
||||
<tbody>
|
||||
<% for item in @list: %>
|
||||
<tr class="u-center<% if item.done: %> is-grayed-out<% end %>" data-id="<%- item.id %>">
|
||||
<tr class="u-center js-callerLog <% if item.done: %> is-grayed-out<% end %>" data-id="<%- item.id %>">
|
||||
<td class="table-checkbox u-positionOrigin">
|
||||
<label class="checkbox-replacement checkbox-replacement--fullscreen<% if item.disabled is true: %> is-disabled<% end %>">
|
||||
<input type="checkbox" class="js-check"<% if item.done: %> checked<% end %><% if item.disabled is true: %> disabled<% end %>>
|
||||
|
|
|
@ -4,6 +4,7 @@ class CtiController < ApplicationController
|
|||
prepend_before_action { authentication_check(permission: 'cti.agent') }
|
||||
|
||||
# list current caller log
|
||||
# GET /api/v1/cti/log
|
||||
def index
|
||||
backends = [
|
||||
{
|
||||
|
@ -29,6 +30,7 @@ class CtiController < ApplicationController
|
|||
end
|
||||
|
||||
# set caller log to done
|
||||
# POST /api/v1/cti/done/:id
|
||||
def done
|
||||
log = Cti::Log.find(params['id'])
|
||||
log.done = params['done']
|
||||
|
@ -36,4 +38,17 @@ class CtiController < ApplicationController
|
|||
render json: {}
|
||||
end
|
||||
|
||||
# sets for all given ids the caller log to done
|
||||
# POST /api/v1/cti/done/bulk
|
||||
def done_bulk
|
||||
|
||||
log_ids = params['ids'] || []
|
||||
log_ids.each do |log_id|
|
||||
log = Cti::Log.find(log_id)
|
||||
log.done = true
|
||||
log.save!
|
||||
end
|
||||
render json: {}
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
Zammad::Application.routes.draw do
|
||||
api_path = Rails.configuration.api_path
|
||||
|
||||
match '/api/v1/cti/log', to: 'cti#index', via: :get
|
||||
match '/api/v1/cti/done/:id', to: 'cti#done', via: :post
|
||||
match api_path + '/cti/log', to: 'cti#index', via: :get
|
||||
match api_path + '/cti/done/bulk', to: 'cti#done_bulk', via: :post
|
||||
match api_path + '/cti/done/:id', to: 'cti#done', via: :post
|
||||
|
||||
end
|
||||
|
|
|
@ -5,6 +5,7 @@ FactoryBot.define do
|
|||
from { '4930609854180' }
|
||||
to { '4930609811111' }
|
||||
call_id { (Cti::Log.pluck(:call_id).map(&:to_i).max || 0).next } # has SQL UNIQUE constraint
|
||||
done { false }
|
||||
|
||||
trait :with_preferences do
|
||||
preferences { Cti::CallerId.get_comment_preferences(from, 'from')&.last }
|
||||
|
|
|
@ -795,5 +795,42 @@ RSpec.describe 'Integration CTI', type: :request do
|
|||
expect(log.duration_talking_time).to be_nil
|
||||
|
||||
end
|
||||
|
||||
it 'flags caller_log as done' do
|
||||
|
||||
cti_log1 = create(:cti_log)
|
||||
log = Cti::Log.find(cti_log1.id)
|
||||
expect(log.done).to eq(false)
|
||||
|
||||
authenticated_as(agent_user)
|
||||
post "/api/v1/cti/done/#{cti_log1.id}", params: {
|
||||
done: true
|
||||
}
|
||||
expect(response).to have_http_status(:ok)
|
||||
|
||||
log = Cti::Log.find(cti_log1.id)
|
||||
expect(log.done).to eq(true)
|
||||
end
|
||||
|
||||
it 'flags all caller_logs as done via done_bulk' do
|
||||
|
||||
cti_log1 = create(:cti_log)
|
||||
cti_log2 = create(:cti_log)
|
||||
|
||||
log = Cti::Log.find(cti_log1.id)
|
||||
expect(log.done).to eq(false)
|
||||
|
||||
authenticated_as(agent_user)
|
||||
post '/api/v1/cti/done/bulk', params: {
|
||||
ids: [cti_log1.id, cti_log2.id]
|
||||
}
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
log1 = Cti::Log.find(cti_log1.id)
|
||||
expect(log1.done).to eq(true)
|
||||
|
||||
log2 = Cti::Log.find(cti_log2.id)
|
||||
expect(log2.done).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue