mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-08 21:06:24 +08:00
[SCI-3166] Finalize global activities front end
This commit is contained in:
parent
2e987ceed3
commit
87280f083a
9 changed files with 160 additions and 67 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
(function() {
|
function globalActivitiesInit() {
|
||||||
function initExpandCollapseAllButtons() {
|
function initExpandCollapseAllButtons() {
|
||||||
$('#global-activities-colapse-all').on('click', function() {
|
$('#global-activities-colapse-all').on('click', function() {
|
||||||
$('.activities-group').collapse('hide');
|
$('.activities-group').collapse('hide');
|
||||||
|
@ -13,40 +13,49 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function initExpandCollapseButton() {
|
function initExpandCollapseButton() {
|
||||||
$('.activities-group').on('hide.bs.collapse', function() {
|
$('.activities-group').on('hidden.bs.collapse', function() {
|
||||||
$(this.dataset.buttonLink)
|
$(this.dataset.buttonLink)
|
||||||
.find('.fas').removeClass('fa-caret-down').addClass('fa-caret-right');
|
.find('.fas').removeClass('fa-caret-down').addClass('fa-caret-right');
|
||||||
});
|
});
|
||||||
$('.activities-group').on('show.bs.collapse', function() {
|
$('.activities-group').on('shown.bs.collapse', function() {
|
||||||
$(this.dataset.buttonLink)
|
$(this.dataset.buttonLink)
|
||||||
.find('.fas').removeClass('fa-caret-right').addClass('fa-caret-down');
|
.find('.fas').removeClass('fa-caret-right').addClass('fa-caret-down');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function initShowMoreButton() {
|
function initShowMoreButton() {
|
||||||
var moreButton = $('.btn-more-activities');
|
var moreButton = $('.btn-more-activities');
|
||||||
moreButton.on('click', function(ev) {
|
moreButton.on('click', function(ev) {
|
||||||
|
var filters = GlobalActivitiesFilterPrepareArray();
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
animateSpinner(null, true);
|
animateSpinner(null, true);
|
||||||
|
filters.to_date = moreButton.data('next-date');
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: $('.global-activities_activities-list').data('activities-url'),
|
url: $('.ga-activities-list').data('activities-url'),
|
||||||
data: { from_date: moreButton.data('next-date') },
|
data: filters,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
success: function(json) {
|
success: function(json) {
|
||||||
$('.global-activities_activities-list').html(json.activities_html);
|
$(json.activities_html).appendTo('.ga-activities-list');
|
||||||
if (json.more_activities === true) {
|
if (json.more_activities === true) {
|
||||||
moreButton.data('next-date', json.next_date);
|
moreButton.data('next-date', json.from);
|
||||||
} else {
|
} else {
|
||||||
moreButton.addClass('hidden');
|
moreButton.addClass('hidden');
|
||||||
}
|
}
|
||||||
|
(new globalActivitiesInit()).updateCollapseButton();
|
||||||
animateSpinner(null, false);
|
animateSpinner(null, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (this) {
|
||||||
|
this.updateCollapseButton = function() {
|
||||||
|
initExpandCollapseButton();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
initExpandCollapseAllButtons();
|
initExpandCollapseAllButtons();
|
||||||
initExpandCollapseButton();
|
initExpandCollapseButton();
|
||||||
initShowMoreButton();
|
initShowMoreButton();
|
||||||
}());
|
}
|
||||||
|
|
||||||
|
globalActivitiesInit();
|
||||||
|
|
|
@ -64,6 +64,7 @@ function GlobalActivitiesUpdateTopPaneTags(event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
|
var updateRunning = false;
|
||||||
var selectors = ['team', 'activity', 'user'];
|
var selectors = ['team', 'activity', 'user'];
|
||||||
// Ajax request for object search
|
// Ajax request for object search
|
||||||
var subjectAjaxQuery = {
|
var subjectAjaxQuery = {
|
||||||
|
@ -96,10 +97,46 @@ $(function() {
|
||||||
var subjectCustomDisplay = (state) => {
|
var subjectCustomDisplay = (state) => {
|
||||||
return state.label + ': ' + state.text;
|
return state.label + ': ' + state.text;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// update_filter
|
||||||
|
var reloadActivities = function() {
|
||||||
|
var moreButton = $('.btn-more-activities');
|
||||||
|
if (updateRunning) return false;
|
||||||
|
updateRunning = true;
|
||||||
|
$('.ga-activities-list .activities-day').remove();
|
||||||
|
animateSpinner(null, true);
|
||||||
|
$.ajax({
|
||||||
|
url: $('.ga-activities-list').data('activities-url'),
|
||||||
|
data: GlobalActivitiesFilterPrepareArray(),
|
||||||
|
dataType: 'json',
|
||||||
|
type: 'POST',
|
||||||
|
success: function(json) {
|
||||||
|
$(json.activities_html).appendTo('.ga-activities-list');
|
||||||
|
if (json.more_activities === true) {
|
||||||
|
moreButton.removeClass('hidden');
|
||||||
|
moreButton.data('next-date', json.from);
|
||||||
|
} else {
|
||||||
|
moreButton.addClass('hidden');
|
||||||
|
}
|
||||||
|
(new globalActivitiesInit()).updateCollapseButton();
|
||||||
|
updateRunning = false;
|
||||||
|
animateSpinner(null, false);
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
updateRunning = false;
|
||||||
|
animateSpinner(null, false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// Common selection intialize
|
// Common selection intialize
|
||||||
$.each(selectors, (index, e) => {
|
$.each(selectors, (index, e) => {
|
||||||
$('.ga-side .' + e + '-selector select').select2Multiple({ singleDisplay: true })
|
$('.ga-side .' + e + '-selector select').select2Multiple({ singleDisplay: true })
|
||||||
.on('change', function() { GlobalActivitiesUpdateTopPaneTags(); });
|
.on('change', function() {
|
||||||
|
GlobalActivitiesUpdateTopPaneTags();
|
||||||
|
reloadActivities();
|
||||||
|
});
|
||||||
$('.ga-side .' + e + '-selector .clear').click(function() {
|
$('.ga-side .' + e + '-selector .clear').click(function() {
|
||||||
$('.ga-side .' + e + '-selector select').select2MultipleClearAll();
|
$('.ga-side .' + e + '-selector select').select2MultipleClearAll();
|
||||||
});
|
});
|
||||||
|
@ -110,14 +147,20 @@ $(function() {
|
||||||
customSelection: subjectCustomDisplay,
|
customSelection: subjectCustomDisplay,
|
||||||
unlimitedSize: true
|
unlimitedSize: true
|
||||||
})
|
})
|
||||||
.on('change select2:select', function(e) { GlobalActivitiesUpdateTopPaneTags(e); });
|
.on('change select2:select', function(e) {
|
||||||
|
GlobalActivitiesUpdateTopPaneTags(e);
|
||||||
|
reloadActivities();
|
||||||
|
});
|
||||||
$('.ga-side .subject-selector .clear').click(function() {
|
$('.ga-side .subject-selector .clear').click(function() {
|
||||||
$('.ga-side .subject-selector select').select2MultipleClearAll();
|
$('.ga-side .subject-selector select').select2MultipleClearAll();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.ga-tags-container .clear-container span').click(function() {
|
$('.ga-tags-container .clear-container span').click(function() {
|
||||||
|
updateRunning = true;
|
||||||
$.each(selectors, (index, e) => { $('.ga-side .' + e + '-selector select').select2MultipleClearAll(); });
|
$.each(selectors, (index, e) => { $('.ga-side .' + e + '-selector select').select2MultipleClearAll(); });
|
||||||
$('.ga-side .subject-selector select').select2MultipleClearAll();
|
$('.ga-side .subject-selector select').select2MultipleClearAll();
|
||||||
|
updateRunning = false;
|
||||||
|
reloadActivities();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#calendar-from-date').on('dp.change', function(e) {
|
$('#calendar-from-date').on('dp.change', function(e) {
|
||||||
|
@ -125,6 +168,7 @@ $(function() {
|
||||||
$('#calendar-to-date').data('DateTimePicker').minDate(e.date);
|
$('#calendar-to-date').data('DateTimePicker').minDate(e.date);
|
||||||
dateContainer[0].dataset.periodSelect = $('#calendar-from-date').val() + ' - ' + $('#calendar-to-date').val();
|
dateContainer[0].dataset.periodSelect = $('#calendar-from-date').val() + ' - ' + $('#calendar-to-date').val();
|
||||||
GlobalActivitiesUpdateTopPaneTags();
|
GlobalActivitiesUpdateTopPaneTags();
|
||||||
|
reloadActivities();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#calendar-to-date').on('dp.change', function(e) {
|
$('#calendar-to-date').on('dp.change', function(e) {
|
||||||
|
@ -132,10 +176,10 @@ $(function() {
|
||||||
$('#calendar-from-date').data('DateTimePicker').maxDate(e.date);
|
$('#calendar-from-date').data('DateTimePicker').maxDate(e.date);
|
||||||
dateContainer[0].dataset.periodSelect = $('#calendar-from-date').val() + ' - ' + $('#calendar-to-date').val();
|
dateContainer[0].dataset.periodSelect = $('#calendar-from-date').val() + ' - ' + $('#calendar-to-date').val();
|
||||||
GlobalActivitiesUpdateTopPaneTags();
|
GlobalActivitiesUpdateTopPaneTags();
|
||||||
|
reloadActivities();
|
||||||
});
|
});
|
||||||
|
|
||||||
GlobalActivitiesUpdateTopPaneTags();
|
GlobalActivitiesUpdateTopPaneTags();
|
||||||
});
|
|
||||||
|
|
||||||
$('.date-selector .hot-button').click(function() {
|
$('.date-selector .hot-button').click(function() {
|
||||||
var selectPeriod = this.dataset.period;
|
var selectPeriod = this.dataset.period;
|
||||||
|
@ -151,12 +195,13 @@ $('.date-selector .hot-button').click(function() {
|
||||||
var firstDay = new Date(today.getFullYear(), today.getMonth(), 1);
|
var firstDay = new Date(today.getFullYear(), today.getMonth(), 1);
|
||||||
var lastDay = new Date(today.getFullYear(), today.getMonth() + 1, 0);
|
var lastDay = new Date(today.getFullYear(), today.getMonth() + 1, 0);
|
||||||
var lastMonth = new Date(new Date().setDate(today.getDate() - 30));
|
var lastMonth = new Date(new Date().setDate(today.getDate() - 30));
|
||||||
|
updateRunning = true;
|
||||||
if (selectPeriod === 'today') {
|
if (selectPeriod === 'today') {
|
||||||
toDate.date(today);
|
toDate.date(today);
|
||||||
fromDate.date(today);
|
fromDate.date(today);
|
||||||
} else if (selectPeriod === 'yesterday') {
|
} else if (selectPeriod === 'yesterday') {
|
||||||
fromDate.date(yesterday);
|
|
||||||
toDate.date(yesterday);
|
toDate.date(yesterday);
|
||||||
|
fromDate.date(yesterday);
|
||||||
} else if (selectPeriod === 'this_week') {
|
} else if (selectPeriod === 'this_week') {
|
||||||
toDate.date(sunday);
|
toDate.date(sunday);
|
||||||
fromDate.date(monday);
|
fromDate.date(monday);
|
||||||
|
@ -170,6 +215,9 @@ $('.date-selector .hot-button').click(function() {
|
||||||
toDate.date(today);
|
toDate.date(today);
|
||||||
fromDate.date(lastMonth);
|
fromDate.date(lastMonth);
|
||||||
}
|
}
|
||||||
|
updateRunning = false;
|
||||||
dateContainer[0].dataset.periodSelect = this.innerHTML;
|
dateContainer[0].dataset.periodSelect = this.innerHTML;
|
||||||
GlobalActivitiesUpdateTopPaneTags();
|
GlobalActivitiesUpdateTopPaneTags();
|
||||||
|
reloadActivities();
|
||||||
|
});
|
||||||
});
|
});
|
|
@ -2,6 +2,7 @@
|
||||||
$.fn.extend({
|
$.fn.extend({
|
||||||
select2Multiple: function(config = {}) {
|
select2Multiple: function(config = {}) {
|
||||||
// Adding ID to each block
|
// Adding ID to each block
|
||||||
|
if (this.next().find('.select2-selection').length > 0) return this;
|
||||||
var templateSelection = (state) => {
|
var templateSelection = (state) => {
|
||||||
return $('<span class="select2-block-body" data-select-id="' + state.id + '">'
|
return $('<span class="select2-block-body" data-select-id="' + state.id + '">'
|
||||||
+ (config.customSelection !== undefined ? config.customSelection(state) : state.text)
|
+ (config.customSelection !== undefined ? config.customSelection(state) : state.text)
|
||||||
|
|
|
@ -7,10 +7,16 @@
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
|
|
||||||
.ga-main {
|
.ga-main {
|
||||||
|
border-right: 1px solid $gray-lighter;
|
||||||
|
padding-top: 10px;
|
||||||
|
|
||||||
.ga-activities-list {
|
.ga-activities-list {
|
||||||
grid-area: activities;
|
grid-area: activities;
|
||||||
min-height: 600px;
|
min-height: 600px;
|
||||||
|
|
||||||
|
.activities-day {
|
||||||
|
margin-bottom: 10px
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.activities-counter-label {
|
.activities-counter-label {
|
||||||
|
@ -24,6 +30,15 @@
|
||||||
|
|
||||||
.activities-group-expand-button {
|
.activities-group-expand-button {
|
||||||
color: $color-emperor;
|
color: $color-emperor;
|
||||||
|
|
||||||
|
.fas {
|
||||||
|
display: inline-block;
|
||||||
|
width: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.activities-group{
|
||||||
|
margin-bottom: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.activity-card {
|
.activity-card {
|
||||||
|
@ -51,7 +66,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.ga-side {
|
.ga-side {
|
||||||
border-left: 1px solid $gray-lighter;
|
|
||||||
float: right;
|
float: right;
|
||||||
|
|
||||||
.filter-block {
|
.filter-block {
|
||||||
|
|
|
@ -9,15 +9,18 @@ class GlobalActivitiesController < ApplicationController
|
||||||
@user_list = User.where(id: UserTeam.where(team: current_user.teams).select(:user_id))
|
@user_list = User.where(id: UserTeam.where(team: current_user.teams).select(:user_id))
|
||||||
.distinct
|
.distinct
|
||||||
.pluck(:full_name, :id)
|
.pluck(:full_name, :id)
|
||||||
@grouped_activities, more_activities =
|
@grouped_activities, @more_activities =
|
||||||
ActivitiesService.load_activities(current_user, teams, activity_filters)
|
ActivitiesService.load_activities(current_user, teams, activity_filters)
|
||||||
|
last_day = @grouped_activities.keys.last
|
||||||
|
@next_date = (Date.parse(last_day) - 1.day).strftime("%Y-%m-%d") if last_day
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json do
|
format.json do
|
||||||
render json: {
|
render json: {
|
||||||
activities_html: @grouped_activities,
|
activities_html: render_to_string(
|
||||||
from: @grouped_activities.keys.first,
|
partial: 'activity_list.html.erb'
|
||||||
to: @grouped_activities.keys.last,
|
),
|
||||||
more_activities: more_activities
|
from: @next_date,
|
||||||
|
more_activities: @more_activities
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
format.html do
|
format.html do
|
||||||
|
@ -59,8 +62,16 @@ class GlobalActivitiesController < ApplicationController
|
||||||
private
|
private
|
||||||
|
|
||||||
def activity_filters
|
def activity_filters
|
||||||
|
begin
|
||||||
|
params[:types]=JSON.parse(params[:types])
|
||||||
|
params[:users]=JSON.parse(params[:users])
|
||||||
|
params[:teams]=JSON.parse(params[:teams])
|
||||||
|
params[:subjects]=JSON.parse(params[:subjects])
|
||||||
|
rescue
|
||||||
|
end
|
||||||
|
|
||||||
params.permit(
|
params.permit(
|
||||||
:from_date, :to_date, types: [], subjects: [], users: [], teams: []
|
:from_date, :to_date, types: [], subjects: {}, users: [], teams: []
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -20,17 +20,21 @@ class ActivitiesService
|
||||||
|
|
||||||
if filters[:from_date] && filters[:to_date]
|
if filters[:from_date] && filters[:to_date]
|
||||||
activities = query.where(
|
activities = query.where(
|
||||||
'created_at <= :from AND created_at >= :to',
|
'created_at >= :from AND created_at <= :to',
|
||||||
from: Time.zone.parse(filters[:from_date]).beginning_of_day.utc,
|
from: Time.zone.parse(filters[:from_date]).beginning_of_day.utc,
|
||||||
to: Time.zone.parse(filters[:to_date]).end_of_day.utc
|
to: Time.zone.parse(filters[:to_date]).end_of_day.utc
|
||||||
)
|
)
|
||||||
elsif filters[:from_date] && !filters[:to_date]
|
elsif filters[:from_date] && !filters[:to_date]
|
||||||
activities = query.where(
|
activities = query.where(
|
||||||
'created_at <= :from',
|
'created_at >= :from',
|
||||||
from: Time.zone.parse(filters[:from_date]).beginning_of_day.utc
|
from: Time.zone.parse(filters[:from_date]).beginning_of_day.utc
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
activities = query
|
activities = query.where(
|
||||||
|
'created_at >= :from AND created_at <= :to',
|
||||||
|
from: Time.now.beginning_of_day.utc,
|
||||||
|
to: Time.now.end_of_day.utc
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
activities = activities.order(created_at: :desc)
|
activities = activities.order(created_at: :desc)
|
||||||
|
@ -44,12 +48,12 @@ class ActivitiesService
|
||||||
|
|
||||||
last_date = results.keys.last
|
last_date = results.keys.last
|
||||||
activities = query.where(
|
activities = query.where(
|
||||||
'created_at <= :from AND created_at >= :to',
|
'created_at >= :from AND created_at <= :to',
|
||||||
from: Time.zone.parse(last_date).beginning_of_day.utc,
|
from: Time.zone.parse(last_date).beginning_of_day.utc,
|
||||||
to: Time.zone.parse(last_date).end_of_day.utc
|
to: Time.zone.parse(last_date).end_of_day.utc
|
||||||
)
|
)
|
||||||
more_left = query.where(
|
more_left = query.where(
|
||||||
'created_at < :from',
|
'created_at > :from',
|
||||||
from: Time.zone.parse(last_date).end_of_day.utc
|
from: Time.zone.parse(last_date).end_of_day.utc
|
||||||
).exists?
|
).exists?
|
||||||
results[last_date] = activities.to_a
|
results[last_date] = activities.to_a
|
||||||
|
|
|
@ -1,18 +1,23 @@
|
||||||
<div class="activity-card">
|
<div class="activity-card">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
|
<% if activity.old_activity? %>
|
||||||
|
<%= activity.message.html_safe %>
|
||||||
|
<% else %>
|
||||||
<% if activity.owner.present? %>
|
<% if activity.owner.present? %>
|
||||||
<%= popover_for_user_name(activity.owner, activity.team, false, true) %>
|
<%= popover_for_user_name(activity.owner, activity.team, false, true) %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<strong><%= activity.owner_id %></strong>
|
<strong><%= activity.owner_id %></strong>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= generate_activity_content(activity) %>
|
<%= generate_activity_content(activity) %>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="pull-left activity-timestamp">
|
<div class="pull-left activity-timestamp">
|
||||||
<%= activity.created_at.strftime('%H:%M') %>
|
<%= activity.created_at.strftime('%H:%M') %>
|
||||||
</div>
|
</div>
|
||||||
<div class="row navigational-breadcrumbs">
|
<div class="row navigational-breadcrumbs">
|
||||||
|
<% unless activity.old_activity? %>
|
||||||
<% if activity.subject_type.present? %>
|
<% if activity.subject_type.present? %>
|
||||||
<%= render partial: "global_activities/references/#{activity.subject_type.underscore}.html.erb",
|
<%= render partial: "global_activities/references/#{activity.subject_type.underscore}.html.erb",
|
||||||
locals: { subject: activity.subject, breadcrumbs: activity.values[:breadcrumbs] } %>
|
locals: { subject: activity.subject, breadcrumbs: activity.values[:breadcrumbs] } %>
|
||||||
|
@ -20,5 +25,6 @@
|
||||||
<%= render partial: "global_activities/references/result.html.erb",
|
<%= render partial: "global_activities/references/result.html.erb",
|
||||||
locals: { subject: activity.subject, breadcrumbs: activity.values[:breadcrumbs] } %>
|
locals: { subject: activity.subject, breadcrumbs: activity.values[:breadcrumbs] } %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<% @grouped_activities.each do |date, activities| %>
|
<% @grouped_activities.each do |date, activities| %>
|
||||||
<div class="row">
|
<div class="row activities-day">
|
||||||
<div class="col-sm-4 col-md-2">
|
<div class="col-sm-4 col-md-2">
|
||||||
<a class="activities-group-expand-button"
|
<a class="activities-group-expand-button"
|
||||||
href="#"
|
href="javascript:void(0);"
|
||||||
id="activities-group-<%= date %>-button"
|
id="activities-group-<%= date %>-button"
|
||||||
data-toggle="collapse"
|
data-toggle="collapse"
|
||||||
data-turbolinks="false"
|
data-turbolinks="false"
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20190227110801) do
|
ActiveRecord::Schema.define(version: 20190227110801) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
|
|
Loading…
Add table
Reference in a new issue