From 901750269b9c57b272254c31dd4018d534e2e698 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Wed, 26 Aug 2015 11:36:12 +0200 Subject: [PATCH] clean up ruby code --- .../sonar-web/src/main/js/apps/account/app.js | 2 +- .../src/main/js/apps/source-viewer/app.js | 1 + .../src/main/js/apps/update-center/app.js | 2 +- .../common/handlebars-extensions.js | 4 +-- .../src/main/js/components/shared/avatar.jsx | 4 +-- .../sonar-web/src/main/js/libs/application.js | 4 +-- server/sonar-web/src/main/js/libs/inputs.js | 6 ++-- server/sonar-web/src/main/js/main.js | 6 ++-- .../WEB-INF/app/views/layouts/_head.html.erb | 35 +++++++++++-------- server/sonar-web/test/medium/base.html | 26 ++++++++------ server/sonar-web/test/medium/test-main.js | 4 +-- .../test/medium/update-center.spec.js | 2 +- .../sonar-web/test/unit/application.spec.js | 4 ++- 13 files changed, 56 insertions(+), 44 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/account/app.js b/server/sonar-web/src/main/js/apps/account/app.js index 7559a916e48..efe802f1383 100644 --- a/server/sonar-web/src/main/js/apps/account/app.js +++ b/server/sonar-web/src/main/js/apps/account/app.js @@ -3,7 +3,7 @@ define([ ], function (ChangePasswordView) { var $ = jQuery; - var shouldShowAvatars = window.SS && window.SS.lf && window.SS.lf.enableGravatar; + var shouldShowAvatars = window.sonar.properties['sonar.lf.enableGravatar']; var favorites = $('.js-account-favorites tr'); function showExtraFavorites () { diff --git a/server/sonar-web/src/main/js/apps/source-viewer/app.js b/server/sonar-web/src/main/js/apps/source-viewer/app.js index 31b6047d152..f9ccf31b248 100644 --- a/server/sonar-web/src/main/js/apps/source-viewer/app.js +++ b/server/sonar-web/src/main/js/apps/source-viewer/app.js @@ -20,6 +20,7 @@ define([ }; App.on('start', function (options) { + console.log(options); if (options.component) { init.call(App, options); } diff --git a/server/sonar-web/src/main/js/apps/update-center/app.js b/server/sonar-web/src/main/js/apps/update-center/app.js index 4630c21b4fe..8a98b3699f6 100644 --- a/server/sonar-web/src/main/js/apps/update-center/app.js +++ b/server/sonar-web/src/main/js/apps/update-center/app.js @@ -15,7 +15,7 @@ define([ init = function (options) { // State this.state = new Backbone.Model({ - updateCenterActive: window.SS.updateCenterActive + updateCenterActive: window.sonar.properties['sonar.updatecenter.activate'] }); // Layout diff --git a/server/sonar-web/src/main/js/components/common/handlebars-extensions.js b/server/sonar-web/src/main/js/components/common/handlebars-extensions.js index 7ebf6a4d470..f9eb1b70e2f 100644 --- a/server/sonar-web/src/main/js/components/common/handlebars-extensions.js +++ b/server/sonar-web/src/main/js/components/common/handlebars-extensions.js @@ -567,14 +567,14 @@ }); Handlebars.registerHelper('ifShowAvatars', function (options) { - var cond = window.SS && window.SS.lf && window.SS.lf.enableGravatar; + var cond = window.sonar.properties['sonar.lf.enableGravatar']; return cond ? options.fn(this) : options.inverse(this); }); Handlebars.registerHelper('avatarHelper', function (email, size) { // double the size for high pixel density screens var emailHash = window.md5((email || '').trim()), - url = ('' + window.SS.lf.gravatarServerUrl) + url = ('' + window.sonar.properties['sonar.lf.gravatarServerUrl']) .replace('{EMAIL_MD5}', emailHash) .replace('{SIZE}', size * 2); return new Handlebars.SafeString( diff --git a/server/sonar-web/src/main/js/components/shared/avatar.jsx b/server/sonar-web/src/main/js/components/shared/avatar.jsx index 2f596bf3a0d..10f74ac42a9 100644 --- a/server/sonar-web/src/main/js/components/shared/avatar.jsx +++ b/server/sonar-web/src/main/js/components/shared/avatar.jsx @@ -7,12 +7,12 @@ export default React.createClass({ }, render() { - const shouldShowAvatar = window.SS && window.SS.lf && window.SS.lf.enableGravatar; + const shouldShowAvatar = window.sonar.properties['sonar.lf.enableGravatar']; if (!shouldShowAvatar) { return null; } const emailHash = window.md5(this.props.email || '').trim(); - const url = ('' + window.SS.lf.gravatarServerUrl) + const url = ('' + window.sonar.properties['sonar.lf.gravatarServerUrl']) .replace('{EMAIL_MD5}', emailHash) .replace('{SIZE}', this.props.size * 2); return {this.props.email}/; diff --git a/server/sonar-web/src/main/js/libs/application.js b/server/sonar-web/src/main/js/libs/application.js index 122916e825b..335ca996ec8 100644 --- a/server/sonar-web/src/main/js/libs/application.js +++ b/server/sonar-web/src/main/js/libs/application.js @@ -444,7 +444,7 @@ window.fileFromPath = function (path) { if (value === 0) { return '0'; } - var hoursInDay = window.SS.hoursInDay || 8, + var hoursInDay = window.sonar.properties['sonar.technicalDebt.hoursInDay'], isNegative = value < 0, absValue = Math.abs(value); var days = Math.floor(absValue / hoursInDay / 60); @@ -464,7 +464,7 @@ window.fileFromPath = function (path) { if (value === 0) { return '0'; } - var hoursInDay = window.SS.hoursInDay || 8, + var hoursInDay = window.sonar.properties['sonar.technicalDebt.hoursInDay'], isNegative = value < 0, absValue = Math.abs(value); var days = Math.floor(absValue / hoursInDay / 60); diff --git a/server/sonar-web/src/main/js/libs/inputs.js b/server/sonar-web/src/main/js/libs/inputs.js index 8ca5407d71d..5e92a3bc0bb 100644 --- a/server/sonar-web/src/main/js/libs/inputs.js +++ b/server/sonar-web/src/main/js/libs/inputs.js @@ -21,7 +21,7 @@ if (!value) { return value; } else { - return (days * window.SS.hoursInDay + hours) * 60 + minutes; + return (days * window.sonar.properties['sonar.technicalDebt.hoursInDay'] + hours) * 60 + minutes; } } @@ -33,8 +33,8 @@ if (!/^\d+$/.test(value)) { return value; } - days = Math.floor(value / (window.SS.hoursInDay * 60)); - hours = Math.floor((value - days * window.SS.hoursInDay * 60) / 60); + days = Math.floor(value / (window.sonar.properties['sonar.technicalDebt.hoursInDay'] * 60)); + hours = Math.floor((value - days * window.sonar.properties['sonar.technicalDebt.hoursInDay'] * 60) / 60); minutes = value % 60; result = []; if (days > 0) { diff --git a/server/sonar-web/src/main/js/main.js b/server/sonar-web/src/main/js/main.js index 6083556bd70..3ef8b64dd9d 100644 --- a/server/sonar-web/src/main/js/main.js +++ b/server/sonar-web/src/main/js/main.js @@ -1,6 +1,6 @@ require.config({ baseUrl: window.baseUrl + '/js', - urlArgs: 'v=' + window.sonarVersion, + urlArgs: 'v=' + window.sonar.version, paths: { 'react': 'libs/third-party/react-with-addons', 'underscore': 'libs/shim/underscore-shim', @@ -15,8 +15,8 @@ require([ './components/common/processes' ], function (App) { new App({ - space: window.space, - componentKey: window.component, + space: window.sonar.space, + componentKey: window.sonar.component, lang: window.pageLang }).start(); }); diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb index aebfb8e361d..49289197059 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb @@ -6,6 +6,13 @@ end component = @project component = @resource unless @project || selected_section == Navigation::SECTION_HOME + + space = 'global' + if selected_section == Navigation::SECTION_RESOURCE + space = 'component' + elsif selected_section == Navigation::SECTION_CONFIGURATION + space = 'settings' + end %> @@ -35,28 +42,26 @@ diff --git a/server/sonar-web/test/medium/base.html b/server/sonar-web/test/medium/base.html index a3eba79d7be..3d3f558d487 100644 --- a/server/sonar-web/test/medium/base.html +++ b/server/sonar-web/test/medium/base.html @@ -4,21 +4,25 @@ diff --git a/server/sonar-web/test/medium/test-main.js b/server/sonar-web/test/medium/test-main.js index 50631c08218..bf3e1881339 100644 --- a/server/sonar-web/test/medium/test-main.js +++ b/server/sonar-web/test/medium/test-main.js @@ -23,8 +23,8 @@ require([ jQuery.mockjax({ url: '/api/navigation/component', responseText: '{"key":"org.codehaus.sonar:sonar","uuid":"uuid","name":"SonarQube","isComparable":true,"canBeFavorite":true,"isFavorite":true,"dashboards":[{"key":109,"name":"Dev"},{"key":1,"name":"Dashboard"},{"key":2,"name":"SQALE"},{"key":8,"name":"Hotspots"},{"key":88,"name":"Issues"},{"key":18,"name":"TimeMachine"},{"key":13,"name":"QA"},{"key":59,"name":"By Developers"}],"version":"5.2-SNAPSHOT","snapshotDate":"2015-08-25T10:37:21+0200","extensions":[],"breadcrumbs":[{"key":"org.codehaus.sonar:sonar","name":"SonarQube","qualifier":"TRK"}]}' }); window.App = new App({ - space: window.space, - componentKey: window.component, + space: window.sonar.space, + componentKey: window.sonar.component, lang: window.pageLang }); window.App.start(); diff --git a/server/sonar-web/test/medium/update-center.spec.js b/server/sonar-web/test/medium/update-center.spec.js index 88b1d8e8a98..326cdfbf6ec 100644 --- a/server/sonar-web/test/medium/update-center.spec.js +++ b/server/sonar-web/test/medium/update-center.spec.js @@ -97,7 +97,7 @@ define(function (require) { .mockFromFile('/api/plugins/updates', 'update-center-spec/updates.json') .mockFromFile('/api/plugins/pending', 'update-center-spec/pending.json') .execute(function () { - window.SS.updateCenterActive = false; + window.sonar.properties['sonar.updatecenter.activate'] = false; }) .startApp('update-center/app') .checkElementExist('.js-plugin-name') diff --git a/server/sonar-web/test/unit/application.spec.js b/server/sonar-web/test/unit/application.spec.js index b3f7e76c433..9178732019f 100644 --- a/server/sonar-web/test/unit/application.spec.js +++ b/server/sonar-web/test/unit/application.spec.js @@ -70,7 +70,9 @@ define(function (require) { 'work_duration.x_minutes': '{0}min', 'work_duration.about': '~ {0}' }; - window.SS = { hoursInDay: HOURS_IN_DAY }; + window.sonar = {}; + window.sonar.properties = {}; + window.sonar.properties['sonar.technicalDebt.hoursInDay'] = HOURS_IN_DAY; }); bdd.describe('#formatMeasure()', function () { -- 2.39.5