Skip to content

Commit

Permalink
Remove global js imports (#542)
Browse files Browse the repository at this point in the history
Removes most of the global imports and provides, redone highchart importing as per their website, remove the local copy of the regression plugin in favor of the copy on npm, and remove oauth token grabbing from logged out users.
  • Loading branch information
BatedUrGonnaDie authored Apr 16, 2019
1 parent 3662d67 commit 660b2ad
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 639 deletions.
8 changes: 5 additions & 3 deletions app/javascript/charts/box_plot.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {logoBlue} from '../colors.js'
import {quantile} from '../stats.js'
import Highcharts from 'highcharts'
const Highcharts = require('highcharts')
require('highcharts/modules/exporting')(Highcharts)
require('highcharts/highcharts-more')(Highcharts)
const moment = require('moment')

import {logoBlue} from '../colors.js'
import {quantile} from '../stats.js'

const buildBoxPlot = (run, chartOptions = {}) => {
if (document.getElementById('box-plot') === null) {
Expand Down
8 changes: 4 additions & 4 deletions app/javascript/charts/playtime.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Highcharts from 'highcharts'
import Exporting from 'highcharts/modules/exporting'
Exporting(Highcharts)
const Highcharts = require('highcharts')
require('highcharts/modules/exporting')(Highcharts)
const moment = require('moment')

import 'vendor/highcharts-regression'
require('highcharts-regression')(Highcharts)

const buildPlaytimeChart = function(run, chartOptions = {}) {
if (document.getElementById('playtime-chart') === null) {
Expand Down
6 changes: 3 additions & 3 deletions app/javascript/charts/run_duration.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Highcharts from 'highcharts'
import Exporting from 'highcharts/modules/exporting'
Exporting(Highcharts)
const Highcharts = require('highcharts')
require('highcharts/modules/exporting')(Highcharts)
const moment = require('moment')

const buildRunDurationChart = function(run, chartOptions) {
if (document.getElementById('run-duration-chart') === null ) {
Expand Down
6 changes: 3 additions & 3 deletions app/javascript/charts/segment_duration.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Highcharts from 'highcharts'
import Exporting from 'highcharts/modules/exporting'
Exporting(Highcharts)
const Highcharts = require('highcharts')
require('highcharts/modules/exporting')(Highcharts)
const moment = require('moment')

const buildSegmentDurationChart = function(timing, segment, chartOptions) {
if (document.getElementById(`segment-duration-chart-${segment.id}`) === null) {
Expand Down
12 changes: 4 additions & 8 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@ import "jquery"
require("@rails/ujs").start()
require("turbolinks").start()
require("channels")
import "moment"
import "moment-duration-format"
import "clipboard"
import * as Cookies from "js-cookie"
const moment = require('moment')
const momentDurationFormatSetup = require('moment-duration-format')

momentDurationFormatSetup(moment)

// Using Google charts for now (a script tag in app/views/layouts/admin/application.slim) because Chartkick + Highcharts
// doesn't seem to include axes, and tooltips don't include years (?) with no clear resolution
import Chartkick from "chartkick"
window.Chartkick = Chartkick

global.moment = moment
global.Clipboard = clipboard
global.Cookies = Cookies

import "../ad_cleanup.js"
import "../analytics.js"
import "../convert.js"
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/settings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const Clipboard = require('clipboard')

document.addEventListener('turbolinks:load', () => {
clipboard = new Clipboard('.clipboard-btn')

Expand Down
2 changes: 0 additions & 2 deletions app/javascript/timeline.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Highcharts from 'highcharts'

document.addEventListener('mouseover', event => {
const segment = event.target.closest('.split')
if (segment === null) {
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const urlHashToObject = function(hash) {

document.addEventListener('turbolinks:load', () => {
// Protect dev modes that haven't set up a client yet
if (process.env.SPLITSIO_CLIENT_ID === undefined) {
if (process.env.SPLITSIO_CLIENT_ID === undefined || gon.user === null) {
return
}

Expand Down
Loading

0 comments on commit 660b2ad

Please sign in to comment.