Add my spent time block

This commit is contained in:
Alexander Meindl 2020-08-10 18:28:52 +02:00
parent 0216478cf9
commit 8605261171
18 changed files with 66 additions and 79 deletions

View File

@ -338,23 +338,22 @@ module DashboardsHelper
news: news }
end
def render_timelog_block(block, _block_definition, settings, _dashboard)
def render_my_spent_time_block(block, block_definition, settings, dashboard)
days = settings[:days].to_i
days = 7 if days < 1 || days > 365
entries = TimeEntry
.where("#{TimeEntry.table_name}.user_id = ? AND #{TimeEntry.table_name}.spent_on BETWEEN ? AND ?",
User.current.id, User.current.today - (days - 1), User.current.today)
.joins(:activity, :project)
.references(issue: %i[tracker status])
.includes(issue: %i[tracker status])
.order("#{TimeEntry.table_name}.spent_on DESC,
#{Project.table_name}.name ASC,
#{Tracker.table_name}.position ASC, #{Issue.table_name}.id ASC")
.to_a
entries_by_day = entries.group_by(&:spent_on)
scope = TimeEntry.where user_id: User.current.id
scope = scope.where(project_id: dashboard.content_project.id) unless dashboard.content_project.nil?
render partial: 'dashboards/blocks/timelog', locals: { block: block, entries: entries, entries_by_day: entries_by_day, days: days }
entries_today = scope.where(spent_on: User.current.today)
entries_days = scope.where(spent_on: User.current.today - (days - 1)..User.current.today)
render partial: 'dashboards/blocks/my_spent_time',
locals: { block: block,
block_definition: block_definition,
entries_today: entries_today,
entries_days: entries_days,
days: days }
end
def activity_dashboard_data(settings, dashboard)

View File

@ -48,7 +48,7 @@ class DashboardContent
permission: :view_news },
'documents' => { label: l(:label_document_plural),
permission: :view_documents },
'timelog' => { label: l(:label_spent_time_static),
'my_spent_time' => { label: l(:label_my_spent_time),
permission: :view_time_entries },
'feed' => { label: l(:label_additionals_feed),
max_occurs: DashboardContent::MAX_MULTIPLE_OCCURS,

View File

@ -0,0 +1,38 @@
h3 = block_definition[:label]
- if @can_edit
div id="#{block}-settings" style='display: none;'
= form_tag(_update_layout_setting_dashboard_path(@project, @dashboard), remote: true) do
.box
p
label
= l(:button_show)
' :
= text_field_tag 'settings[my_spent_time][days]', days, size: 6
= l(:label_day_plural)
p
= submit_tag l(:button_save)
'
= link_to_function l(:button_cancel), "$('#my_spent_time-settings').toggle();"
ul.reporting-list
li.today
= l :label_today
' :
= l_hours_short entries_today.sum(&:hours)
li.days
= l :label_last_n_days, days
' :
= l_hours_short entries_days.sum(&:hours)
= link_to l(:label_spent_time), _time_entries_path(@project, nil, user_id: 'me')
- if User.current.allowed_to?(:log_time, nil, global: true)
'
= link_to l(:button_log_time),
_new_time_entry_path(@project, nil),
class: 'icon-only icon-add',
title: l(:button_log_time)
- else
p.nodata = l :label_no_data

View File

@ -1,4 +1,4 @@
h3.icon.icon-news = l(:label_news_latest)
h3.icon.icon-news = l :label_news_latest
- if @can_edit
div id="#{block}-settings" style='display: none;'

View File

@ -1,63 +0,0 @@
h3
= link_to l(:label_spent_time), time_entries_path(user_id: 'me')
| (
= l(:label_last_n_days, days)
' :
= l_hours_short entries.sum(&:hours)
| )
- if User.current.allowed_to?(:log_time, nil, global: true)
'
= link_to l(:button_log_time), new_time_entry_path, class: 'icon-only icon-add', title: l(:button_log_time)
- if @can_edit
div id="#{block}-settings" style='display: none;'
= form_tag(_update_layout_setting_dashboard_path(@project, @dashboard), remote: true) do
.box
p
label
= l(:button_show)
' :
= text_field_tag 'settings[timelog][days]', days, size: 6
= l(:label_day_plural)
p
= submit_tag l(:button_save)
'
= link_to_function l(:button_cancel), "$('#timelog-settings').toggle();"
- if entries.any?
= form_tag({}, data: { cm_url: time_entries_context_menu_path }) do
table.list.time-entries.odd-even
thead
tr
th = l(:label_activity)
th = l(:label_project)
th = l(:field_comments)
th = l(:field_hours)
th
tbody
- entries_by_day.keys.sort.reverse_each do |day|
tr.odd
td
strong
= day == User.current.today ? l(:label_today).titleize : format_date(day)
td[colspan='2']
td.hours
em
= html_hours(format_hours(entries_by_day[day].sum(&:hours)))
td
- entries_by_day[day].each do |entry|
tr.time-entry.hascontextmenu id="time-entry-#{entry.id}"
td.activity
= check_box_tag('ids[]', entry.id, false, style: 'display: none;', id: nil)
= entry.activity
td.subject
= entry.project
= h(' - ') + link_to_issue(entry.issue, truncate: 50) if entry.issue
td.comments
= entry.comments
td.hours
= html_hours(format_hours(entry.hours))
td.buttons
= link_to_context_menu
- else
p.nodata = l :label_no_data

View File

@ -190,3 +190,4 @@ cs:
top_wiki_help: "Zde můžete definovat obsah a nastavení vaší Wiki."
wiki_pdf_remove_attachments_info: "Pokud je aktivní, připojené soubory Wiki se nebudou zobrazovat v zobrazení PDF."
wiki_pdf_remove_title_info: "Pokud je aktivní, informace o názvu Wiki se nebudou zobrazovat v zobrazení PDF."
label_my_spent_time: My spent time

View File

@ -190,3 +190,4 @@ de:
top_wiki_help: Hier kannst Du Inhalte und Einstellungen bzg. der Wiki festlegen.
wiki_pdf_remove_attachments_info: Wenn aktiv, werden die an der Wiki Seite angehängten Dateien nicht in der PDF Ansicht angezeigt.
wiki_pdf_remove_title_info: Wenn aktiv, wird der Wiki Titel nicht in der PDF Ansicht angezeigt.
label_my_spent_time: Meine aufgewendete Zeit

View File

@ -190,3 +190,4 @@ en:
top_wiki_help: Here you can define contents and settings for your Wiki.
wiki_pdf_remove_attachments_info: When active the attached Wiki files will not be displayed in PDF view.
wiki_pdf_remove_title_info: When active the Wiki title info will not be displayed in PDF view.
label_my_spent_time: My spent time

View File

@ -190,3 +190,4 @@ es:
top_wiki_help: "Aquí puede definir contenidos y configuracioens para su Wiki."
wiki_pdf_remove_attachments_info: "Cuando está activa, los adjuntos no serán mostrados en los PDF."
wiki_pdf_remove_title_info: "Cuando está activa, el título de la Wiki no será mostrado en los PDF."
label_my_spent_time: My spent time

View File

@ -190,3 +190,4 @@ fr:
top_wiki_help: "Ici vous pouvez définir le contenu et les paramètres de votre Wiki."
wiki_pdf_remove_attachments_info: "Lorsqu'ils sont actifs, les fichiers Wiki joints ne seront pas affichés en vue PDF."
wiki_pdf_remove_title_info: "Lorsqu'elle est active, l'information sur le titre du wiki ne sera pas affichée dans la vue PDF."
label_my_spent_time: My spent time

View File

@ -190,3 +190,4 @@ it:
top_wiki_help: "Qui puoi definire contenuti e impostazioni per il tuo Wiki."
wiki_pdf_remove_attachments_info: "Quando è attivo, il Wiki file allegati non verranno visualizzati nella vista PDF."
wiki_pdf_remove_title_info: "Quando è attivo, le informazioni sul titolo del Wiki non verranno visualizzate nella vista PDF."
label_my_spent_time: My spent time

View File

@ -190,3 +190,4 @@ ja:
top_wiki_help: Here you can define contents and settings for your Wiki.
wiki_pdf_remove_attachments_info: When active the attached Wiki files will not be displayed in PDF view.
wiki_pdf_remove_title_info: When active the Wiki title info will not be displayed in PDF view.
label_my_spent_time: My spent time

View File

@ -190,3 +190,4 @@ ko:
top_wiki_help: 여기에서 위키의 내용과 설정을 정의 할 수 있습니다.
wiki_pdf_remove_attachments_info: 활성화 된 경우 첨부 된 Wiki 파일은 PDF보기에 표시되지 않습니다.
wiki_pdf_remove_title_info: 활성화되면 위키 제목 정보가 PDF보기에 표시되지 않습니다.
label_my_spent_time: My spent time

View File

@ -190,3 +190,4 @@ pl:
top_wiki_help: "Tutaj możesz zdefiniować zawartość i ustawienia dla swojej Wiki."
wiki_pdf_remove_attachments_info: "Gdy jest aktywny, załączone pliki Wiki nie będą wyświetlane w widoku PDF."
wiki_pdf_remove_title_info: "Gdy jest aktywny, informacja o tytule Wiki nie będzie wyświetlana w widoku PDF."
label_my_spent_time: My spent time

View File

@ -190,3 +190,4 @@ ru:
top_wiki_help: "Здесь вы можете определить содержимое и настройки для вашей Вики."
wiki_pdf_remove_attachments_info: "Если флажок установлен, вложенные Вики-файлы не будут отображаться в PDF-формате."
wiki_pdf_remove_title_info: "При активации этого параметра информация о названии Вики не будет отображаться в PDF-формате."
label_my_spent_time: My spent time

View File

@ -190,3 +190,4 @@
top_wiki_help: "您可以在此自訂Wiki的內容和設定。"
wiki_pdf_remove_attachments_info: "當啟用時Wiki附件將不會顯示在PDF中。"
wiki_pdf_remove_title_info: "當啟用時Wiki標題訊息不會顯示在PDF中"
label_my_spent_time: My spent time

View File

@ -190,3 +190,4 @@ zh:
top_wiki_help: 您可以在此定义 WIKI 的内容及设置。
wiki_pdf_remove_attachments_info: 当启用时WIKI 附件将不会显示在PDF视图中。
wiki_pdf_remove_title_info: 当启用时WIKI 标题信息将不会显示在PDF视图中。
label_my_spent_time: My spent time

View File

@ -10,6 +10,7 @@ system_default_welcome:
:layout:
top:
- issuequery
- my_spent_time
left:
- text
- legacy_left