diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2015-05-18 16:29:19 +0200 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2015-05-19 18:20:09 +0200 |
commit | e59e4aa2c06a57566f148f4217d286461231ae58 (patch) | |
tree | ad0918eb06b2474a6c71997b7ff573bbb93e0170 /server/sonar-web/src/main/js/workspace | |
parent | 8d82c9cf9ba88c1517604b4063ad0fc2a9a1bb9a (diff) | |
download | sonarqube-e59e4aa2c06a57566f148f4217d286461231ae58.tar.gz sonarqube-e59e4aa2c06a57566f148f4217d286461231ae58.zip |
change web structure: separate components
Diffstat (limited to 'server/sonar-web/src/main/js/workspace')
9 files changed, 0 insertions, 619 deletions
diff --git a/server/sonar-web/src/main/js/workspace/main.js b/server/sonar-web/src/main/js/workspace/main.js deleted file mode 100644 index 6a468b36a7f..00000000000 --- a/server/sonar-web/src/main/js/workspace/main.js +++ /dev/null @@ -1,144 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -define([ - 'workspace/models/item', - 'workspace/models/items', - 'workspace/views/items-view', - 'workspace/views/viewer-view', - 'workspace/views/rule-view' -], function (Item, Items, ItemsView, ViewerView, RuleView) { - - var $ = jQuery, - - instance = null, - - Workspace = function () { - if (instance != null) { - throw new Error('Cannot instantiate more than one Workspace, use Workspace.getInstance()'); - } - this.initialize(); - }; - - Workspace.prototype = { - initialize: function () { - var that = this; - - this.items = new Items(); - this.items.load(); - this.items.on('change', function () { - that.save(); - }); - - this.itemsView = new ItemsView({ collection: this.items }); - this.itemsView.render().$el.appendTo(document.body); - this.itemsView.on('click', function (model) { - that.open(model); - }); - }, - - save: function () { - this.items.save(); - }, - - addComponent: function (model) { - if (!this.items.has(model)) { - this.items.add(model); - } - this.save(); - }, - - open: function (options) { - var model = typeof options.toJSON === 'function' ? options : new Item(options); - if (!model.isValid()) { - throw new Error(model.validationError); - } - this.addComponent(model); - if (model.isComponent()) { - this.showComponentViewer(model); - } - if (model.isRule()) { - this.showRule(model); - } - }, - - openComponent: function (options) { - return this.open(_.extend(options, { type: 'component' })); - }, - - openRule: function (options) { - return this.open(_.extend(options, { type: 'rule' })); - }, - - showViewer: function (Viewer, model) { - var that = this; - if (this.viewerView != null) { - this.viewerView.model.trigger('hideViewer'); - this.viewerView.close(); - } - $('.source-viewer').addClass('with-workspace'); - model.trigger('showViewer'); - this.viewerView = new Viewer({ model: model }); - this.viewerView - .on('viewerMinimize', function () { - model.trigger('hideViewer'); - that.closeComponentViewer(); - }) - .on('viewerClose', function (m) { - that.closeComponentViewer(); - m.destroy(); - }); - this.viewerView.render().$el.appendTo(document.body); - }, - - showComponentViewer: function (model) { - this.showViewer(ViewerView, model); - }, - - closeComponentViewer: function () { - if (this.viewerView != null) { - this.viewerView.close(); - $('.with-workspace').removeClass('with-workspace'); - } - }, - - showRule: function (model) { - this.showViewer(RuleView, model); - this.fetchRule(model); - }, - - fetchRule: function (model) { - var url = baseUrl + '/api/rules/show', - options = { key: model.get('key') }; - return $.get(url, options).done(function (r) { - model.set(r.rule); - }); - } - }; - - Workspace.getInstance = function () { - if (instance == null) { - instance = new Workspace(); - } - return instance; - }; - - return Workspace.getInstance(); - -}); diff --git a/server/sonar-web/src/main/js/workspace/models/item.js b/server/sonar-web/src/main/js/workspace/models/item.js deleted file mode 100644 index 9bbe1db8110..00000000000 --- a/server/sonar-web/src/main/js/workspace/models/item.js +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -define(function () { - - return Backbone.Model.extend({ - - validate: function () { - if (!this.has('type')) { - return 'type is missing'; - } - if (this.get('type') === 'component' && !this.has('uuid')) { - return 'uuid is missing'; - } - if (this.get('type') === 'rule' && !this.has('key')) { - return 'key is missing'; - } - }, - - isComponent: function () { - return this.get('type') === 'component'; - }, - - isRule: function () { - return this.get('type') === 'rule'; - }, - - destroy: function (options) { - this.stopListening(); - this.trigger('destroy', this, this.collection, options); - } - }); - -}); diff --git a/server/sonar-web/src/main/js/workspace/models/items.js b/server/sonar-web/src/main/js/workspace/models/items.js deleted file mode 100644 index 7a4bde3bd02..00000000000 --- a/server/sonar-web/src/main/js/workspace/models/items.js +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -define(['workspace/models/item'], function (Item) { - - var STORAGE_KEY = 'sonarqube-workspace'; - - return Backbone.Collection.extend({ - model: Item, - - initialize: function () { - this.on('remove', this.save); - }, - - save: function () { - var dump = JSON.stringify(this.toJSON()); - window.localStorage.setItem(STORAGE_KEY, dump); - }, - - load: function () { - var dump = window.localStorage.getItem(STORAGE_KEY); - if (dump != null) { - try { - var parsed = JSON.parse(dump); - this.reset(parsed); - } catch (err) { } - } - }, - - has: function (model) { - var forComponent = model.isComponent() && this.findWhere({ uuid: model.get('uuid') }) != null, - forRule = model.isRule() && this.findWhere({ key: model.get('key') }) != null; - return forComponent || forRule; - } - }); - -}); diff --git a/server/sonar-web/src/main/js/workspace/views/base-viewer-view.js b/server/sonar-web/src/main/js/workspace/views/base-viewer-view.js deleted file mode 100644 index 20396a7cb51..00000000000 --- a/server/sonar-web/src/main/js/workspace/views/base-viewer-view.js +++ /dev/null @@ -1,57 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -define([ - 'workspace/views/viewer-header-view' -], function (HeaderView) { - - return Marionette.Layout.extend({ - className: 'workspace-viewer', - - modelEvents: { - 'destroy': 'close' - }, - - regions: { - headerRegion: '.workspace-viewer-header', - viewerRegion: '.workspace-viewer-container' - }, - - onRender: function () { - this.showHeader(); - this.$('.workspace-viewer-container').isolatedScroll(); - }, - - onViewerMinimize: function () { - this.trigger('viewerMinimize'); - }, - - onViewerClose: function () { - this.trigger('viewerClose', this.model); - }, - - showHeader: function () { - var headerView = new HeaderView({ model: this.model }); - this.listenTo(headerView, 'viewerMinimize', this.onViewerMinimize); - this.listenTo(headerView, 'viewerClose', this.onViewerClose); - this.headerRegion.show(headerView); - } - }); - -}); diff --git a/server/sonar-web/src/main/js/workspace/views/item-view.js b/server/sonar-web/src/main/js/workspace/views/item-view.js deleted file mode 100644 index ad593a73905..00000000000 --- a/server/sonar-web/src/main/js/workspace/views/item-view.js +++ /dev/null @@ -1,60 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -define([ - 'templates/workspace' -], function () { - - return Marionette.ItemView.extend({ - tagName: 'li', - className: 'workspace-nav-item', - template: Templates['workspace-item'], - - modelEvents: { - 'change': 'render', - 'showViewer': 'onViewerShow', - 'hideViewer': 'onViewerHide' - }, - - events: { - 'click': 'onClick', - 'click .js-close': 'onCloseClick' - }, - - onClick: function (e) { - e.preventDefault(); - this.options.collectionView.trigger('click', this.model); - }, - - onCloseClick: function (e) { - e.preventDefault(); - e.stopPropagation(); - this.model.destroy(); - }, - - onViewerShow: function () { - this.$el.addClass('hidden'); - }, - - onViewerHide: function () { - this.$el.removeClass('hidden'); - } - }); - -}); diff --git a/server/sonar-web/src/main/js/workspace/views/items-view.js b/server/sonar-web/src/main/js/workspace/views/items-view.js deleted file mode 100644 index e6c721bf089..00000000000 --- a/server/sonar-web/src/main/js/workspace/views/items-view.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -define([ - 'workspace/views/item-view', - 'templates/workspace' -], function (ItemView) { - - return Marionette.CompositeView.extend({ - className: 'workspace-nav', - template: Templates['workspace-items'], - itemViewContainer: '.workspace-nav-list', - itemView: ItemView, - - itemViewOptions: function () { - return { collectionView: this }; - } - }); - -}); diff --git a/server/sonar-web/src/main/js/workspace/views/rule-view.js b/server/sonar-web/src/main/js/workspace/views/rule-view.js deleted file mode 100644 index 2bb983ad1de..00000000000 --- a/server/sonar-web/src/main/js/workspace/views/rule-view.js +++ /dev/null @@ -1,49 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -define([ - 'workspace/views/base-viewer-view', - 'templates/workspace' -], function (BaseView) { - - return BaseView.extend({ - template: Templates['workspace-rule'], - - modelEvents: { - 'destroy': 'close', - 'change': 'render' - }, - - onRender: function () { - BaseView.prototype.onRender.apply(this, arguments); - this.$('[data-toggle="tooltip"]').tooltip({ container: 'body' }); - }, - - onClose: function () { - this.$('[data-toggle="tooltip"]').tooltip('destroy'); - }, - - serializeData: function () { - return _.extend(Marionette.Layout.prototype.serializeData.apply(this, arguments), { - allTags: _.union(this.model.get('sysTags'), this.model.get('tags')) - }); - } - }); - -}); diff --git a/server/sonar-web/src/main/js/workspace/views/viewer-header-view.js b/server/sonar-web/src/main/js/workspace/views/viewer-header-view.js deleted file mode 100644 index 4f15baf29b2..00000000000 --- a/server/sonar-web/src/main/js/workspace/views/viewer-header-view.js +++ /dev/null @@ -1,114 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -define([ - 'templates/workspace' -], function () { - - var $ = jQuery; - - return Marionette.ItemView.extend({ - template: Templates['workspace-viewer-header'], - - modelEvents: { - 'change': 'render' - }, - - events: { - 'mousedown .js-resize': 'onResizeClick', - - 'click .js-minimize': 'onMinimizeClick', - 'click .js-full-screen': 'onFullScreenClick', - 'click .js-normal-size': 'onNormalSizeClick', - 'click .js-close': 'onCloseClick' - }, - - onRender: function () { - this.$('[data-toggle="tooltip"]').tooltip({ container: 'body' }); - this.$('.js-normal-size').addClass('hidden'); - }, - - onClose: function () { - this.$('[data-toggle="tooltip"]').tooltip('destroy'); - $('.tooltip').remove(); - }, - - onResizeClick: function (e) { - e.preventDefault(); - this.startResizing(e); - }, - - onMinimizeClick: function (e) { - e.preventDefault(); - this.trigger('viewerMinimize'); - }, - - onFullScreenClick: function (e) { - e.preventDefault(); - this.toFullScreen(); - }, - - onNormalSizeClick: function (e) { - e.preventDefault(); - this.toNormalSize(); - }, - - onCloseClick: function (e) { - e.preventDefault(); - this.trigger('viewerClose'); - }, - - startResizing: function (e) { - this.initialResizePosition = e.clientY; - this.initialResizeHeight = $('.workspace-viewer-container').height(); - var processResizing = _.bind(this.processResizing, this), - stopResizing = _.bind(this.stopResizing, this); - $('body') - .on('mousemove.workspace', processResizing) - .on('mouseup.workspace', stopResizing); - }, - - processResizing: function (e) { - var currentResizePosition = e.clientY, - resizeDelta = this.initialResizePosition - currentResizePosition, - height = this.initialResizeHeight + resizeDelta; - $('.workspace-viewer-container').height(height); - }, - - stopResizing: function () { - $('body') - .off('mousemove.workspace') - .off('mouseup.workspace'); - }, - - toFullScreen: function () { - this.$('.js-normal-size').removeClass('hidden'); - this.$('.js-full-screen').addClass('hidden'); - this.initialResizeHeight = $('.workspace-viewer-container').height(); - $('.workspace-viewer-container').height('9999px'); - }, - - toNormalSize: function () { - this.$('.js-normal-size').addClass('hidden'); - this.$('.js-full-screen').removeClass('hidden'); - $('.workspace-viewer-container').height(this.initialResizeHeight); - } - }); - -}); diff --git a/server/sonar-web/src/main/js/workspace/views/viewer-view.js b/server/sonar-web/src/main/js/workspace/views/viewer-view.js deleted file mode 100644 index 171186f6179..00000000000 --- a/server/sonar-web/src/main/js/workspace/views/viewer-view.js +++ /dev/null @@ -1,56 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -define([ - 'workspace/views/base-viewer-view', - 'source-viewer/viewer', - 'templates/workspace' -], function (BaseView, SourceViewer) { - - return BaseView.extend({ - template: Templates['workspace-viewer'], - - onRender: function () { - BaseView.prototype.onRender.apply(this, arguments); - this.showViewer(); - }, - - showViewer: function () { - if (SourceViewer == null) { - SourceViewer = require('source-viewer/viewer'); - } - var that = this, - viewer = new SourceViewer(), - options = this.model.toJSON(); - viewer.open(this.model.get('uuid'), { workspace: true }); - viewer.on('loaded', function () { - that.model.set({ - name: viewer.model.get('name'), - q: viewer.model.get('q') - }); - if (options.line != null) { - viewer.highlightLine(options.line); - viewer.scrollToLine(options.line); - } - }); - this.viewerRegion.show(viewer); - } - }); - -}); |