#1741 do not show merged issues in reports

This commit is contained in:
Muhammad Nuzaihan 2018-01-15 19:54:26 +08:00
parent df33dc1d71
commit 84121e9fda
4 changed files with 307 additions and 6 deletions

View file

@ -22,6 +22,12 @@ class Report
dataDownload: true, dataDownload: true,
adapter: Report::TicketGenericTime, adapter: Report::TicketGenericTime,
params: { field: 'created_at' }, params: { field: 'created_at' },
condition: {
'state' => {
'operator' => 'is not',
'value' => 'merged'
}
}
}, },
{ {
name: 'closed', name: 'closed',
@ -30,6 +36,12 @@ class Report
dataDownload: true, dataDownload: true,
adapter: Report::TicketGenericTime, adapter: Report::TicketGenericTime,
params: { field: 'close_at' }, params: { field: 'close_at' },
condition: {
'state' => {
'operator' => 'is not',
'value' => 'merged'
}
}
}, },
{ {
name: 'backlog', name: 'backlog',
@ -37,6 +49,12 @@ class Report
selected: true, selected: true,
dataDownload: false, dataDownload: false,
adapter: Report::TicketBacklog, adapter: Report::TicketBacklog,
condition: {
'state' => {
'operator' => 'is not',
'value' => 'merged'
}
}
}, },
{ {
name: 'first_solution', name: 'first_solution',
@ -44,6 +62,12 @@ class Report
selected: false, selected: false,
dataDownload: true, dataDownload: true,
adapter: Report::TicketFirstSolution, adapter: Report::TicketFirstSolution,
condition: {
'ticket_state.name' => {
'operator' => 'is not',
'value' => 'merged'
}
}
}, },
{ {
name: 'reopened', name: 'reopened',
@ -51,6 +75,12 @@ class Report
selected: false, selected: false,
dataDownload: true, dataDownload: true,
adapter: Report::TicketReopened, adapter: Report::TicketReopened,
condition: {
'ticket_state.name' => {
'operator' => 'is not',
'value' => 'merged'
}
}
}, },
{ {
name: 'movedin', name: 'movedin',
@ -59,6 +89,12 @@ class Report
dataDownload: true, dataDownload: true,
adapter: Report::TicketMoved, adapter: Report::TicketMoved,
params: { type: 'in' }, params: { type: 'in' },
condition: {
'ticket_state.name' => {
'operator' => 'is not',
'value' => 'merged'
}
}
}, },
{ {
name: 'movedout', name: 'movedout',
@ -67,6 +103,12 @@ class Report
dataDownload: true, dataDownload: true,
adapter: Report::TicketMoved, adapter: Report::TicketMoved,
params: { type: 'out' }, params: { type: 'out' },
condition: {
'ticket_state.name' => {
'operator' => 'is not',
'value' => 'merged'
}
}
}, },
] ]
config[:metric][:count][:backend] = backend config[:metric][:count][:backend] = backend

View file

@ -528,6 +528,9 @@ condition example
elsif selector[0] == 'article' elsif selector[0] == 'article'
tables += ', ticket_articles articles' tables += ', ticket_articles articles'
query += 'tickets.id = articles.ticket_id' query += 'tickets.id = articles.ticket_id'
elsif selector[0] == 'ticket_state'
tables += ', ticket_states'
query += 'tickets.state_id = ticket_states.id'
else else
raise "invalid selector #{attribute.inspect}->#{selector.inspect}" raise "invalid selector #{attribute.inspect}->#{selector.inspect}"
end end

View file

@ -459,7 +459,7 @@ get count of tickets and tickets which match on selector
elsif data['operator'] == 'contains not' elsif data['operator'] == 'contains not'
query_must_not.push t query_must_not.push t
else else
raise "unknown operator '#{data['operator']}'" raise "unknown operator '#{data['operator']}' for #{key}"
end end
end end
end end

View file

@ -245,6 +245,34 @@ class ReportTest < ActiveSupport::TestCase
created_by_id: 1, created_by_id: 1,
) )
@ticket8 = Ticket.create!(
title: 'test 8',
group: group1,
customer_id: 2,
state: Ticket::State.lookup(name: 'merged'),
priority: Ticket::Priority.lookup(name: '2 normal'),
close_at: '2015-11-02 12:30:00 UTC',
created_at: '2015-11-02 12:30:00 UTC',
updated_at: '2015-11-02 12:30:00 UTC',
updated_by_id: 1,
created_by_id: 1,
)
Ticket::Article.create!(
ticket_id: @ticket8.id,
from: 'some_sender@example.com',
to: 'some_recipient@example.com',
subject: 'some subject',
message_id: 'some@id',
body: 'some message article_outbound',
internal: false,
sender: Ticket::Article::Sender.where(name: 'Agent').first,
type: Ticket::Article::Type.where(name: 'email').first,
created_at: '2015-11-02 12:30:00 UTC',
updated_at: '2015-11-02 12:30:00 UTC',
updated_by_id: 1,
created_by_id: 1,
)
# execute background jobs # execute background jobs
Scheduler.worker(true) Scheduler.worker(true)
@ -276,7 +304,7 @@ class ReportTest < ActiveSupport::TestCase
assert_equal(0, result[7]) assert_equal(0, result[7])
assert_equal(0, result[8]) assert_equal(0, result[8])
assert_equal(2, result[9]) assert_equal(2, result[9])
assert_equal(1, result[10]) assert_equal(2, result[10])
assert_equal(0, result[11]) assert_equal(0, result[11])
assert_nil(result[12]) assert_nil(result[12])
@ -289,7 +317,8 @@ class ReportTest < ActiveSupport::TestCase
assert_equal(@ticket5.id, result[:ticket_ids][0]) assert_equal(@ticket5.id, result[:ticket_ids][0])
assert_equal(@ticket6.id, result[:ticket_ids][1]) assert_equal(@ticket6.id, result[:ticket_ids][1])
assert_equal(@ticket7.id, result[:ticket_ids][2]) assert_equal(@ticket7.id, result[:ticket_ids][2])
assert_nil(result[:ticket_ids][3]) assert_equal(@ticket8.id, result[:ticket_ids][3])
assert_nil(result[:ticket_ids][4])
# month - with selector #1 # month - with selector #1
result = Report::TicketFirstSolution.aggs( result = Report::TicketFirstSolution.aggs(
@ -332,6 +361,47 @@ class ReportTest < ActiveSupport::TestCase
assert_equal(@ticket5.id, result[:ticket_ids][0]) assert_equal(@ticket5.id, result[:ticket_ids][0])
assert_nil(result[:ticket_ids][1]) assert_nil(result[:ticket_ids][1])
# month - with merged tickets selector
result = Report::TicketFirstSolution.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
interval: 'month', # year, quarter, month, week, day, hour, minute, second
selector: {
'ticket_state.name' => {
'operator' => 'is not',
'value' => 'merged',
}
}, # ticket selector to get only a collection of tickets
)
assert(result)
assert_equal(0, result[0])
assert_equal(0, result[1])
assert_equal(0, result[2])
assert_equal(0, result[3])
assert_equal(0, result[4])
assert_equal(0, result[5])
assert_equal(0, result[6])
assert_equal(0, result[7])
assert_equal(0, result[8])
assert_equal(2, result[9])
assert_equal(1, result[10])
assert_equal(0, result[11])
assert_nil(result[12])
result = Report::TicketFirstSolution.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
selector: {
'ticket_state.name' => {
'operator' => 'is not',
'value' => 'merged',
}
}, # ticket selector to get only a collection of tickets
)
assert(result)
assert_equal(@ticket5.id, result[:ticket_ids][0])
assert_nil(result[:ticket_ids][3])
# month - with selector #2 # month - with selector #2
result = Report::TicketFirstSolution.aggs( result = Report::TicketFirstSolution.aggs(
range_start: '2015-01-01T00:00:00Z', range_start: '2015-01-01T00:00:00Z',
@ -355,7 +425,7 @@ class ReportTest < ActiveSupport::TestCase
assert_equal(0, result[7]) assert_equal(0, result[7])
assert_equal(0, result[8]) assert_equal(0, result[8])
assert_equal(1, result[9]) assert_equal(1, result[9])
assert_equal(1, result[10]) assert_equal(2, result[10])
assert_equal(0, result[11]) assert_equal(0, result[11])
assert_nil(result[12]) assert_nil(result[12])
@ -372,7 +442,8 @@ class ReportTest < ActiveSupport::TestCase
assert(result) assert(result)
assert_equal(@ticket6.id, result[:ticket_ids][0]) assert_equal(@ticket6.id, result[:ticket_ids][0])
assert_equal(@ticket7.id, result[:ticket_ids][1]) assert_equal(@ticket7.id, result[:ticket_ids][1])
assert_nil(result[:ticket_ids][2]) assert_equal(@ticket8.id, result[:ticket_ids][2])
assert_nil(result[:ticket_ids][3])
# week # week
result = Report::TicketFirstSolution.aggs( result = Report::TicketFirstSolution.aggs(
@ -611,6 +682,94 @@ class ReportTest < ActiveSupport::TestCase
assert(result) assert(result)
assert_nil(result[:ticket_ids][0]) assert_nil(result[:ticket_ids][0])
# month - reopened with merge selector
result = Report::TicketReopened.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
interval: 'month', # year, quarter, month, week, day, hour, minute, second
selector: {
'ticket_state.name' => {
'operator' => 'is not',
'value' => 'merged',
}
}, # ticket selector to get only a collection of tickets
)
assert(result)
assert_equal(0, result[0])
assert_equal(0, result[1])
assert_equal(0, result[2])
assert_equal(0, result[3])
assert_equal(0, result[4])
assert_equal(0, result[5])
assert_equal(0, result[6])
assert_equal(0, result[7])
assert_equal(0, result[8])
assert_equal(1, result[9])
assert_equal(0, result[10])
assert_equal(0, result[11])
assert_nil(result[12])
result = Report::TicketReopened.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
selector: {
'ticket_state.name' => {
'operator' => 'is not',
'value' => 'merged',
}
}, # ticket selector to get only a collection of tickets
)
assert(result)
assert_equal(@ticket5.id, result[:ticket_ids][0])
assert_nil(result[:ticket_ids][1])
# move in/out without merged status
result = Report::TicketMoved.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
interval: 'month', # year, quarter, month, week, day, hour, minute, second
selector: {
'ticket_state.name' => {
'operator' => 'is not',
'value' => 'merged',
}
}, # ticket selector to get only a collection of tickets
params: {
type: 'in',
},
)
assert(result)
assert_equal(0, result[0])
assert_equal(0, result[1])
assert_equal(0, result[2])
assert_equal(0, result[3])
assert_equal(0, result[4])
assert_equal(0, result[5])
assert_equal(0, result[6])
assert_equal(0, result[7])
assert_equal(0, result[8])
assert_equal(0, result[9])
assert_equal(0, result[10])
assert_equal(0, result[11])
assert_nil(result[12])
result = Report::TicketMoved.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
selector: {
'ticket.group_id' => {
'operator' => 'is',
'value' => [Group.lookup(name: 'Users').id],
}
}, # ticket selector to get only a collection of tickets
params: {
type: 'in',
},
)
assert(result)
assert_equal(@ticket1.id, result[:ticket_ids][0])
assert_nil(result[:ticket_ids][1])
# move in/out # move in/out
result = Report::TicketMoved.aggs( result = Report::TicketMoved.aggs(
range_start: '2015-01-01T00:00:00Z', range_start: '2015-01-01T00:00:00Z',
@ -658,6 +817,52 @@ class ReportTest < ActiveSupport::TestCase
assert_equal(@ticket1.id, result[:ticket_ids][0]) assert_equal(@ticket1.id, result[:ticket_ids][0])
assert_nil(result[:ticket_ids][1]) assert_nil(result[:ticket_ids][1])
# out without merged tickets
result = Report::TicketMoved.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
interval: 'month', # year, quarter, month, week, day, hour, minute, second
selector: {
'ticket_state.name' => {
'operator' => 'is not',
'value' => 'merged',
}
}, # ticket selector to get only a collection of tickets
params: {
type: 'out',
},
)
assert(result)
assert_equal(0, result[0])
assert_equal(0, result[1])
assert_equal(0, result[2])
assert_equal(0, result[3])
assert_equal(0, result[4])
assert_equal(0, result[5])
assert_equal(0, result[6])
assert_equal(0, result[7])
assert_equal(0, result[8])
assert_equal(0, result[9])
assert_equal(0, result[10])
assert_equal(0, result[11])
assert_nil(result[12])
result = Report::TicketMoved.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
selector: {
'ticket_state.name' => {
'operator' => 'is not',
'value' => 'merged',
}
}, # ticket selector to get only a collection of tickets
params: {
type: 'out',
},
)
assert(result)
assert_nil(result[:ticket_ids][0])
# out # out
result = Report::TicketMoved.aggs( result = Report::TicketMoved.aggs(
range_start: '2015-01-01T00:00:00Z', range_start: '2015-01-01T00:00:00Z',
@ -724,7 +929,7 @@ class ReportTest < ActiveSupport::TestCase
assert_equal(0, result[7]) assert_equal(0, result[7])
assert_equal(0, result[8]) assert_equal(0, result[8])
assert_equal(6, result[9]) assert_equal(6, result[9])
assert_equal(1, result[10]) assert_equal(2, result[10])
assert_equal(0, result[11]) assert_equal(0, result[11])
assert_nil(result[12]) assert_nil(result[12])
@ -734,6 +939,57 @@ class ReportTest < ActiveSupport::TestCase
selector: {}, # ticket selector to get only a collection of tickets selector: {}, # ticket selector to get only a collection of tickets
params: { field: 'created_at' }, params: { field: 'created_at' },
) )
assert(result)
assert_equal(@ticket8.id, result[:ticket_ids][0].to_i)
assert_equal(@ticket7.id, result[:ticket_ids][1].to_i)
assert_equal(@ticket6.id, result[:ticket_ids][2].to_i)
assert_equal(@ticket5.id, result[:ticket_ids][3].to_i)
assert_equal(@ticket4.id, result[:ticket_ids][4].to_i)
assert_equal(@ticket3.id, result[:ticket_ids][5].to_i)
assert_equal(@ticket2.id, result[:ticket_ids][6].to_i)
assert_equal(@ticket1.id, result[:ticket_ids][7].to_i)
assert_nil(result[:ticket_ids][8])
# create at - selector with merge
result = Report::TicketGenericTime.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
interval: 'month', # year, quarter, month, week, day, hour, minute, second
selector: {
'state' => {
'operator' => 'is not',
'value' => 'merged'
}
}, # ticket selector to get only a collection of tickets
params: { field: 'created_at' },
)
assert(result)
assert_equal(0, result[0])
assert_equal(0, result[1])
assert_equal(0, result[2])
assert_equal(0, result[3])
assert_equal(0, result[4])
assert_equal(0, result[5])
assert_equal(0, result[6])
assert_equal(0, result[7])
assert_equal(0, result[8])
assert_equal(6, result[9])
assert_equal(1, result[10])
assert_equal(0, result[11])
assert_nil(result[12])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
selector: {
'state' => {
'operator' => 'is not',
'value' => 'merged'
}
}, # ticket selector to get only a collection of tickets
params: { field: 'created_at' },
)
assert(result) assert(result)
assert_equal(@ticket7.id, result[:ticket_ids][0].to_i) assert_equal(@ticket7.id, result[:ticket_ids][0].to_i)
assert_equal(@ticket6.id, result[:ticket_ids][1].to_i) assert_equal(@ticket6.id, result[:ticket_ids][1].to_i)