From 9b61c5062f4a47a3b364c014fb8ba411a71bad4d Mon Sep 17 00:00:00 2001 From: benweet Date: Mon, 10 Jun 2013 23:32:34 +0100 Subject: [PATCH] Added Google Analytics --- css/default.css | 3 +- js/core.js | 2 +- js/extensionMgr.js | 13 +++--- js/extensions/buttonSync.js | 30 +++++++++++-- js/extensions/googleAnalytics.js | 65 +++++++++++++++++------------ js/extensions/toc.js | 2 +- js/extensions/workingIndicator.js | 2 +- js/html/buttonSyncSettingsBloc.html | 10 +++++ js/synchronizer.js | 19 ++------- 9 files changed, 92 insertions(+), 54 deletions(-) create mode 100644 js/html/buttonSyncSettingsBloc.html diff --git a/css/default.css b/css/default.css index 85737e23..2c3bfd22 100644 --- a/css/default.css +++ b/css/default.css @@ -553,7 +553,8 @@ div.dropdown-menu i { text-align: left; } -#modal-settings .accordion-inner .form-inline .label-text { +#modal-settings .accordion-inner .form-inline .label-text, +#modal-settings .accordion-inner .control-label { margin: 0 10px; } diff --git a/js/core.js b/js/core.js index 341aa648..0ec52f07 100644 --- a/js/core.js +++ b/js/core.js @@ -17,7 +17,7 @@ define([ // Used for periodic tasks var intervalId = undefined; - var periodicCallbacks = []; + var periodicCallbacks = [extensionMgr.onPeriodicRun]; core.addPeriodicCallback = function(callback) { periodicCallbacks.push(callback); }; diff --git a/js/extensionMgr.js b/js/extensionMgr.js index 8ab92100..ed175b03 100644 --- a/js/extensionMgr.js +++ b/js/extensionMgr.js @@ -40,10 +40,12 @@ define([ } // Return a function that calls every callbacks from extensions - function createHook(hookName) { + function createHook(hookName, noLog) { var callbackList = getExtensionCallbackList(hookName); return function() { - logger.log(hookName, arguments); + if(!noLog) { + logger.log(hookName, arguments); + } var callbackArguments = arguments; _.each(callbackList, function(callback) { callback.apply(null, callbackArguments); @@ -52,8 +54,8 @@ define([ } // Add a Hook to the extensionMgr - function addHook(hookName) { - extensionMgr[hookName] = createHook(hookName); + function addHook(hookName, noLog) { + extensionMgr[hookName] = createHook(hookName, noLog); } // Set extension config @@ -87,7 +89,8 @@ define([ addHook("onMessage"); addHook("onError"); addHook("onOfflineChanged"); - addHook("onAsyncRunning"); + addHook("onAsyncRunning", true); + addHook("onPeriodicRun", true); // To access modules that are loaded after extensions addHook("onFileMgrCreated"); diff --git a/js/extensions/buttonSync.js b/js/extensions/buttonSync.js index 86f1b64f..f0d623f3 100644 --- a/js/extensions/buttonSync.js +++ b/js/extensions/buttonSync.js @@ -1,13 +1,26 @@ define([ "jquery", "underscore", + "utils", "text!html/buttonSync.html", -], function($, _, buttonSyncHTML) { + "text!html/buttonSyncSettingsBloc.html", +], function($, _, utils, buttonSyncHTML, buttonSyncSettingsBlocHTML) { var buttonSync = { extensionId: "buttonSync", extensionName: 'Button "Synchronize"', - settingsBloc: '

Adds a "Synchronize documents" button in the navigation bar.

' + defaultConfig: { + syncPeriod: 180000 + }, + settingsBloc: buttonSyncSettingsBlocHTML + }; + + buttonSync.onLoadSettings = function() { + utils.setInputValue("#input-sync-period", buttonSync.config.syncPeriod); + }; + + buttonSync.onSaveSettings = function(newConfig, event) { + newConfig.syncPeriod = utils.getInputIntValue("#input-sync-period", undefined, 0); }; var button = undefined; @@ -32,10 +45,21 @@ define([ synchronizer = synchronizerParameter; }; + // Run sync periodically + var lastSync = 0; + buttonSync.onPeriodicRun = function() { + if(viewerMode === true || !buttonSync.config.syncPeriod || lastSync + buttonSync.config.syncPeriod > utils.currentTime) { + return; + } + if(synchronizer.sync() === true) { + lastSync = utils.currentTime; + } + }; + buttonSync.onCreateButton = function() { button = $(buttonSyncHTML).click(function() { if(!$(this).hasClass("disabled")) { - synchronizer.forceSync(); + synchronizer.sync(); } }); return button; diff --git a/js/extensions/googleAnalytics.js b/js/extensions/googleAnalytics.js index 156df549..af1c17bb 100644 --- a/js/extensions/googleAnalytics.js +++ b/js/extensions/googleAnalytics.js @@ -31,48 +31,48 @@ define([ // Collect informations about user settings _gaq.push([ '_trackEvent', - "settings", + "Settings", 'layoutOrientation', "" + settings.layoutOrientation ]); _gaq.push([ '_trackEvent', - "settings", + "Settings", 'lazyRendering', "" + settings.lazyRendering ]); _gaq.push([ '_trackEvent', - "settings", + "Settings", 'editorFontSize', "" + settings.editorFontSize ]); // Check if user has removed back links _gaq.push([ '_trackEvent', - "settings", - 'defaultContentBacklink', + "Settings", + 'defaultContent backlink', "" + settings.defaultContent.indexOf(MAIN_URL) >= 0 ]); _gaq.push([ '_trackEvent', - "settings", - 'commitMsgBacklink', + "Settings", + 'commitMsg backlink', "" + settings.commitMsg.indexOf(MAIN_URL) >= 0 ]); // Check if user has changed sshProxy _gaq.push([ '_trackEvent', - "settings", - 'sshProxyChanged', + "Settings", + 'sshProxy changed', "" + settings.sshProxy != SSH_PROXY_URL ]); // Check if extensions have been disabled _.each(settings.extensionSettings, function(config, extensionId) { _gaq.push([ '_trackEvent', - "extensions", - extensionId + "Enabled", + "Extensions", + extensionId + " enabled", "" + config.enabled ]); }); @@ -97,25 +97,34 @@ define([ init(); }; - var currentAction = "No action"; - googleAnalytics.onSyncRunning = function() { - currentAction = "Sync"; + var currentAction = "Unknown"; + var startTime = 0; + googleAnalytics.onSyncRunning = function(isRunning) { + if(isRunning === true) { + currentAction = "Sync"; + startTime = new Date().getTime(); + } }; - googleAnalytics.onPublishRunning = function() { - currentAction = "Publish"; + googleAnalytics.onPublishRunning = function(isRunning) { + if(isRunning === true) { + currentAction = "Publish"; + startTime = new Date().getTime(); + } }; googleAnalytics.onAsyncRunning = function(isRunning) { if(isRunning === false) { - currentAction = "No action"; + currentAction = "Unknown"; } }; - // Log sync frequency + // Log sync time googleAnalytics.onSyncSuccess = function() { + var endTime = new Date().getTime(); _gaq.push([ - '_trackEvent', + '_trackTiming', 'Sync', - 'SyncSuccess' + 'SyncTime', + endTime - startTime ]); }; // Log import frequency and provider @@ -128,7 +137,7 @@ define([ _gaq.push([ '_trackEvent', 'Sync', - 'SyncImportProvider', + 'SyncImport provider', provider.providerId ]); }; @@ -142,22 +151,24 @@ define([ _gaq.push([ '_trackEvent', 'Sync', - 'SyncExportProvider', + 'SyncExport provider', syncAttributes.provider.providerId ]); }; - // Log publish frequency and provider + // Log publish time and provider googleAnalytics.onPublishSuccess = function(fileDesc) { + var endTime = new Date().getTime(); _gaq.push([ - '_trackEvent', + '_trackTiming', 'Publish', - 'PublishSuccess' + 'PublishSuccess', + endTime - startTime ]); _.each(fileDesc.publishLocations, function(publishAttributes) { _gaq.push([ '_trackEvent', 'Publish', - 'PublishSuccessProvider', + 'PublishSuccess provider', publishAttributes.provider.providerId ]); }); @@ -167,7 +178,7 @@ define([ _gaq.push([ '_trackEvent', 'Publish', - 'NewPublishProvider', + 'NewPublish provider', publishAttributes.provider.providerId ]); }; diff --git a/js/extensions/toc.js b/js/extensions/toc.js index 7ced2925..b1945563 100644 --- a/js/extensions/toc.js +++ b/js/extensions/toc.js @@ -7,7 +7,7 @@ define([ var toc = { extensionId: "toc", - extensionName: "Table of content", + extensionName: "Table of Content", optional: true, defaultConfig: { marker: "\\[(TOC|toc)\\]" diff --git a/js/extensions/workingIndicator.js b/js/extensions/workingIndicator.js index 31acb065..48e68fac 100644 --- a/js/extensions/workingIndicator.js +++ b/js/extensions/workingIndicator.js @@ -5,7 +5,7 @@ define([ var workingIndicator = { extensionId: "workingIndicator", - extensionName: "Working indicator", + extensionName: "Working Indicator", settingsBloc: '

Displays an animated image when a network operation is running.

' }; diff --git a/js/html/buttonSyncSettingsBloc.html b/js/html/buttonSyncSettingsBloc.html new file mode 100644 index 00000000..9a78bdc8 --- /dev/null +++ b/js/html/buttonSyncSettingsBloc.html @@ -0,0 +1,10 @@ +

Adds a "Synchronize documents" button in the navigation bar.

+
+
+ +
+ ms +
+
+
\ No newline at end of file diff --git a/js/synchronizer.js b/js/synchronizer.js index a5d5c117..9d096204 100644 --- a/js/synchronizer.js +++ b/js/synchronizer.js @@ -41,12 +41,6 @@ define([ }); }); - // Force the synchronization - synchronizer.forceSync = function() { - lastSync = 0; - synchronizer.sync(); - }; - // Recursive function to upload a single file on multiple locations var uploadSyncAttributesList = []; var uploadContent = undefined; @@ -154,16 +148,14 @@ define([ // Main entry point for synchronization var syncRunning = false; - var lastSync = 0; synchronizer.sync = function() { - // If sync is already running or timeout is not reached or offline - if(syncRunning || lastSync + SYNC_PERIOD > utils.currentTime || core.isOffline) { - return; + // If sync is already running or offline + if(syncRunning || core.isOffline) { + return false; } syncRunning = true; extensionMgr.onSyncRunning(true); uploadCycle = true; - lastSync = utils.currentTime; function isError(error) { if(error !== undefined) { @@ -187,11 +179,8 @@ define([ extensionMgr.onSyncSuccess(); }); }); + return true; }; - // Run sync function periodically - if(viewerMode === false) { - core.addPeriodicCallback(synchronizer.sync); - } // Initialize the export dialog function initExportDialog(provider) {