mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-06 21:24:23 +08:00
adds bullet gem [fixes SCI-1578]
This commit is contained in:
parent
6159b18533
commit
ee054f91b8
15 changed files with 184 additions and 60 deletions
1
Gemfile
1
Gemfile
|
@ -92,6 +92,7 @@ group :development, :test do
|
||||||
gem 'rubocop', require: false
|
gem 'rubocop', require: false
|
||||||
gem 'scss_lint', require: false
|
gem 'scss_lint', require: false
|
||||||
gem 'starscope', require: false
|
gem 'starscope', require: false
|
||||||
|
gem 'bullet'
|
||||||
end
|
end
|
||||||
|
|
||||||
group :test do
|
group :test do
|
||||||
|
|
|
@ -105,6 +105,9 @@ GEM
|
||||||
momentjs-rails (>= 2.8.1)
|
momentjs-rails (>= 2.8.1)
|
||||||
bootstrap_form (2.7.0)
|
bootstrap_form (2.7.0)
|
||||||
builder (3.2.3)
|
builder (3.2.3)
|
||||||
|
bullet (5.6.1)
|
||||||
|
activesupport (>= 3.0.0)
|
||||||
|
uniform_notifier (~> 1.10.0)
|
||||||
byebug (9.0.6)
|
byebug (9.0.6)
|
||||||
capybara (2.15.1)
|
capybara (2.15.1)
|
||||||
addressable
|
addressable
|
||||||
|
@ -431,6 +434,7 @@ GEM
|
||||||
execjs (>= 0.3.0, < 3)
|
execjs (>= 0.3.0, < 3)
|
||||||
underscore-rails (1.8.3)
|
underscore-rails (1.8.3)
|
||||||
unicode-display_width (1.3.0)
|
unicode-display_width (1.3.0)
|
||||||
|
uniform_notifier (1.10.0)
|
||||||
warden (1.2.7)
|
warden (1.2.7)
|
||||||
rack (>= 1.0)
|
rack (>= 1.0)
|
||||||
webpacker (2.0)
|
webpacker (2.0)
|
||||||
|
@ -467,6 +471,7 @@ DEPENDENCIES
|
||||||
bootstrap-select-rails
|
bootstrap-select-rails
|
||||||
bootstrap3-datetimepicker-rails (~> 4.15.35)
|
bootstrap3-datetimepicker-rails (~> 4.15.35)
|
||||||
bootstrap_form
|
bootstrap_form
|
||||||
|
bullet
|
||||||
byebug
|
byebug
|
||||||
capybara
|
capybara
|
||||||
commit_param_routing
|
commit_param_routing
|
||||||
|
@ -543,4 +548,4 @@ RUBY VERSION
|
||||||
ruby 2.4.1p111
|
ruby 2.4.1p111
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
1.15.3
|
1.15.4
|
||||||
|
|
50
app/controllers/client_api/teams/teams_controller.rb
Normal file
50
app/controllers/client_api/teams/teams_controller.rb
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
module ClientApi
|
||||||
|
module Teams
|
||||||
|
class TeamsController < ApplicationController
|
||||||
|
include ClientApi::Users::UserTeamsHelper
|
||||||
|
|
||||||
|
def index
|
||||||
|
success_response('/client_api/teams/index',
|
||||||
|
teams: current_user.teams_data)
|
||||||
|
end
|
||||||
|
|
||||||
|
def details
|
||||||
|
team_service = ClientApi::TeamsService.new(id: params[:team_id],
|
||||||
|
current_user: current_user)
|
||||||
|
success_response('/client_api/teams/details',
|
||||||
|
team_service.team_page_details_data)
|
||||||
|
rescue MissingTeamError
|
||||||
|
error_response
|
||||||
|
end
|
||||||
|
|
||||||
|
def change_team
|
||||||
|
team_service = ClientApi::TeamsService.new(id: params[:team_id],
|
||||||
|
current_user: current_user)
|
||||||
|
team_service.change_current_team!
|
||||||
|
success_response('/client_api/teams/index', team_service.teams_data)
|
||||||
|
rescue MissingTeamError
|
||||||
|
error_response
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def success_response(template, locals)
|
||||||
|
respond_to do |format|
|
||||||
|
format.json do
|
||||||
|
render template: template,
|
||||||
|
status: :ok,
|
||||||
|
locals: locals
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def error_response
|
||||||
|
respond_to do |format|
|
||||||
|
format.json do
|
||||||
|
render json: { message: 'Bad boy!' }, status: :bad_request
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,50 +0,0 @@
|
||||||
module ClientApi
|
|
||||||
class TeamsController < ApplicationController
|
|
||||||
include ClientApi::Users::UserTeamsHelper
|
|
||||||
MissingTeamError = Class.new(StandardError)
|
|
||||||
|
|
||||||
def index
|
|
||||||
success_response
|
|
||||||
end
|
|
||||||
|
|
||||||
def change_team
|
|
||||||
change_current_team
|
|
||||||
success_response
|
|
||||||
rescue MissingTeamError
|
|
||||||
error_response
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def success_response
|
|
||||||
respond_to do |format|
|
|
||||||
format.json do
|
|
||||||
render template: '/client_api/teams/index',
|
|
||||||
status: :ok,
|
|
||||||
locals: teams
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def error_response
|
|
||||||
respond_to do |format|
|
|
||||||
format.json do
|
|
||||||
render json: { message: 'Bad boy!' }, status: :bad_request
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def teams
|
|
||||||
{ teams: current_user.teams_data }
|
|
||||||
end
|
|
||||||
|
|
||||||
def change_current_team
|
|
||||||
team_id = params.fetch(:team_id) { raise MissingTeamError }
|
|
||||||
unless current_user.teams.pluck(:id).include? team_id
|
|
||||||
raise MissingTeamError
|
|
||||||
end
|
|
||||||
current_user.update_attribute(:current_team_id, team_id)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
3
app/javascript/packs/app/dom_routes.js
Normal file
3
app/javascript/packs/app/dom_routes.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
// Settings page
|
||||||
|
export const SETTINGS_TEAMS_ROUTE = "/settings/teams";
|
||||||
|
export const SETTINGS_TEAM_ROUTE = "/settings/teams/:id";
|
|
@ -3,7 +3,8 @@ export const ACTIVITIES_PATH = "/client_api/activities";
|
||||||
|
|
||||||
// teams
|
// teams
|
||||||
export const TEAMS_PATH = "/client_api/teams";
|
export const TEAMS_PATH = "/client_api/teams";
|
||||||
export const CHANGE_TEAM_PATH = "/client_api/change_team";
|
export const CHANGE_TEAM_PATH = "/client_api/teams/change_team";
|
||||||
|
export const TEAM_DETAILS_PATH = "/client_api/teams/:team_id/details";
|
||||||
|
|
||||||
// search
|
// search
|
||||||
export const SEARCH_PATH = "/search";
|
export const SEARCH_PATH = "/search";
|
||||||
|
@ -23,7 +24,7 @@ export const CONTACT_US_LINK =
|
||||||
"http://scinote.net/story-of-scinote/#contact-scinote";
|
"http://scinote.net/story-of-scinote/#contact-scinote";
|
||||||
|
|
||||||
// user teams
|
// user teams
|
||||||
export const LEAVE_TEAM_PATH = "/client_api/users/leave_team"
|
export const LEAVE_TEAM_PATH = "/client_api/users/leave_team";
|
||||||
|
|
||||||
// settings
|
// settings
|
||||||
export const SETTINGS_ACCOUNT_PROFILE = "/settings/account/profile";
|
export const SETTINGS_ACCOUNT_PROFILE = "/settings/account/profile";
|
||||||
|
|
|
@ -6,10 +6,15 @@ import { FormattedMessage } from "react-intl";
|
||||||
import Navigation from "../../../shared/navigation";
|
import Navigation from "../../../shared/navigation";
|
||||||
|
|
||||||
import { SETTINGS_ACCOUNT_PROFILE, SETTINGS_TEAMS } from "../../../app/routes";
|
import { SETTINGS_ACCOUNT_PROFILE, SETTINGS_TEAMS } from "../../../app/routes";
|
||||||
|
import {
|
||||||
|
SETTINGS_TEAMS_ROUTE,
|
||||||
|
SETTINGS_TEAM_ROUTE
|
||||||
|
} from "../../../app/dom_routes";
|
||||||
|
|
||||||
import NotFound from "../../../shared/404/NotFound";
|
import NotFound from "../../../shared/404/NotFound";
|
||||||
import SettingsAccount from ".././components/account/SettingsAccount";
|
import SettingsAccount from "./account/SettingsAccount";
|
||||||
import SettingsTeams from ".././components/team/SettingsTeams";
|
import SettingsTeams from "./teams/SettingsTeams";
|
||||||
|
import SettingsTeamPageContainer from "./team/SettingsTeamPageContainer";
|
||||||
|
|
||||||
export default class MainNav extends Component {
|
export default class MainNav extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
@ -57,7 +62,11 @@ export default class MainNav extends Component {
|
||||||
render={() => <Redirect to="/settings/account/profile" />}
|
render={() => <Redirect to="/settings/account/profile" />}
|
||||||
/>
|
/>
|
||||||
<Route path="/settings/account" component={SettingsAccount} />
|
<Route path="/settings/account" component={SettingsAccount} />
|
||||||
<Route path="/settings/teams" component={SettingsTeams} />
|
<Route
|
||||||
|
path={SETTINGS_TEAM_ROUTE}
|
||||||
|
component={SettingsTeamPageContainer}
|
||||||
|
/>
|
||||||
|
<Route path={SETTINGS_TEAMS_ROUTE} component={SettingsTeams} />
|
||||||
<Route component={NotFound} />
|
<Route component={NotFound} />
|
||||||
</Switch>
|
</Switch>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
import React, { Component } from "react";
|
||||||
|
import PropTypes, { number, string, bool } from "prop-types";
|
||||||
|
import styled from "styled-components";
|
||||||
|
import { FormattedMessage } from "react-intl";
|
||||||
|
import axios from "../../../../app/axios";
|
||||||
|
|
||||||
|
import { TEAM_DETAILS_PATH } from "../../../../app/routes";
|
||||||
|
import {
|
||||||
|
BORDER_LIGHT_COLOR,
|
||||||
|
COLOR_CONCRETE
|
||||||
|
} from "../../../../app/constants/colors";
|
||||||
|
|
||||||
|
const Wrapper = styled.div`
|
||||||
|
background: white;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border: 1px solid ${BORDER_LIGHT_COLOR};
|
||||||
|
border-top: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 16px 15px 50px 15px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const TabTitle = styled.div`
|
||||||
|
background-color: ${COLOR_CONCRETE};
|
||||||
|
padding: 15px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
class SettingsTeamPageContainer extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
team: {},
|
||||||
|
users: []
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
const path = TEAM_DETAILS_PATH.replace(":team_id", this.props.params.id);
|
||||||
|
axios.get(path).then(response => {
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<Wrapper>
|
||||||
|
<TabTitle>
|
||||||
|
<FormattedMessage id="settings_page.all_teams" />
|
||||||
|
</TabTitle>
|
||||||
|
</Wrapper>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SettingsTeamPageContainer;
|
|
@ -1,2 +0,0 @@
|
||||||
|
|
||||||
import { LEAVE_TEAM_PATH } from '../../../../../app/routes'
|
|
|
@ -3,9 +3,11 @@ import PropTypes, { func, number, string, bool } from "prop-types";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { Button } from "react-bootstrap";
|
import { Button } from "react-bootstrap";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
import { Link } from "react-router-dom";
|
||||||
import { FormattedMessage } from "react-intl";
|
import { FormattedMessage } from "react-intl";
|
||||||
import { leaveTeamModalShow } from "../../../../../shared/actions/LeaveTeamActions";
|
import { leaveTeamModalShow } from "../../../../../shared/actions/LeaveTeamActions";
|
||||||
import DataTable from "../../../../../shared/data_table";
|
import DataTable from "../../../../../shared/data_table";
|
||||||
|
import { SETTINGS_TEAMS_ROUTE } from "../../../../../app/dom_routes";
|
||||||
|
|
||||||
class TeamsDataTable extends Component {
|
class TeamsDataTable extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
@ -13,6 +15,7 @@ class TeamsDataTable extends Component {
|
||||||
|
|
||||||
this.leaveTeamModal = this.leaveTeamModal.bind(this);
|
this.leaveTeamModal = this.leaveTeamModal.bind(this);
|
||||||
this.leaveTeamButton = this.leaveTeamButton.bind(this);
|
this.leaveTeamButton = this.leaveTeamButton.bind(this);
|
||||||
|
this.linkToTeam = this.linkToTeam.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
leaveTeamModal(e, id) {
|
leaveTeamModal(e, id) {
|
||||||
|
@ -36,6 +39,14 @@ class TeamsDataTable extends Component {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
linkToTeam(name, col) {
|
||||||
|
return (
|
||||||
|
<Link to={`${SETTINGS_TEAMS_ROUTE}/${col.id}`}>
|
||||||
|
{name}
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const options = {
|
const options = {
|
||||||
defaultSortName: "name",
|
defaultSortName: "name",
|
||||||
|
@ -50,6 +61,7 @@ class TeamsDataTable extends Component {
|
||||||
name: "Name",
|
name: "Name",
|
||||||
isKey: false,
|
isKey: false,
|
||||||
textId: "name",
|
textId: "name",
|
||||||
|
dataFormat: this.linkToTeam,
|
||||||
position: 0,
|
position: 0,
|
||||||
dataSort: true
|
dataSort: true
|
||||||
},
|
},
|
23
app/services/client_api/teams_service.rb
Normal file
23
app/services/client_api/teams_service.rb
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
module ClientApi
|
||||||
|
class TeamsService
|
||||||
|
MissingTeamError = Class.new(StandardError)
|
||||||
|
def initialize(arg)
|
||||||
|
team_id = arg.fetch(:team_id) { raise MissingTeamError }
|
||||||
|
@team = Team.find_by_id(team_id)
|
||||||
|
@current_user = arg.fetch(:current_user) { raise MissingTeamError }
|
||||||
|
raise MissingTeamError unless @current_user.teams.include? @team
|
||||||
|
end
|
||||||
|
|
||||||
|
def change_current_team!
|
||||||
|
@current_user.update_attribute(:current_team_id, @team.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def team_page_details_data
|
||||||
|
{ team: @team, users: @team.users.eager_load(:user_teams) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def teams_data
|
||||||
|
{ teams: @current_user.teams_data }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
15
app/views/client_api/teams/details.json.jbuilder
Normal file
15
app/views/client_api/teams/details.json.jbuilder
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
json.team_details do
|
||||||
|
json.id team.id
|
||||||
|
json.created_at team.created_at
|
||||||
|
json.created_by team.created_by
|
||||||
|
json.space_taken team.space_taken
|
||||||
|
json.description team.description
|
||||||
|
json.users users do |user|
|
||||||
|
# json.id team.fetch('id')
|
||||||
|
# json.name team.fetch('name')
|
||||||
|
# json.members team.fetch('members')
|
||||||
|
# json.role retrive_role_name(team.fetch('role') { nil })
|
||||||
|
# json.current_team team.fetch('current_team')
|
||||||
|
# json.can_be_leaved team.fetch('can_be_leaved')
|
||||||
|
end
|
||||||
|
end
|
|
@ -17,8 +17,11 @@ Rails.application.routes.draw do
|
||||||
# activities
|
# activities
|
||||||
get '/activities', to: 'activities#index'
|
get '/activities', to: 'activities#index'
|
||||||
# teams
|
# teams
|
||||||
get '/teams', to: 'teams#index'
|
get '/teams', to: 'teams/teams#index'
|
||||||
|
namespace :teams do
|
||||||
|
get '/:team_id/details', to: 'teams#details'
|
||||||
post '/change_team', to: 'teams#change_team'
|
post '/change_team', to: 'teams#change_team'
|
||||||
|
end
|
||||||
# notifications
|
# notifications
|
||||||
get '/recent_notifications', to: 'notifications#recent_notifications'
|
get '/recent_notifications', to: 'notifications#recent_notifications'
|
||||||
# users
|
# users
|
||||||
|
|
Loading…
Add table
Reference in a new issue