From 5d73e699fe7e3d60b20d3db77a05100e2cde5e2d Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Tue, 12 Sep 2017 15:07:10 +0200 Subject: [PATCH] Refactoring: Removed unneeded Network functionality structure. --- .../app/controllers/network.coffee | 67 ----------- .../javascripts/app/models/network.coffee | 9 -- .../app/models/network_category.coffee | 3 - .../app/models/network_category_type.coffee | 3 - .../app/models/network_privacy.coffee | 3 - .../javascripts/app/views/network.jst.eco | 84 -------------- app/controllers/network_controller.rb | 87 -------------- .../sessions/collection_network.rb | 14 --- app/models/network.rb | 33 ------ config/routes/network.rb | 11 -- db/migrate/20120101000020_create_network.rb | 108 ------------------ db/migrate/20170912123300_remove_network.rb | 18 +++ db/seeds.rb | 2 +- db/seeds/networks.rb | 100 ---------------- 14 files changed, 19 insertions(+), 523 deletions(-) delete mode 100644 app/assets/javascripts/app/controllers/network.coffee delete mode 100644 app/assets/javascripts/app/models/network.coffee delete mode 100644 app/assets/javascripts/app/models/network_category.coffee delete mode 100644 app/assets/javascripts/app/models/network_category_type.coffee delete mode 100644 app/assets/javascripts/app/models/network_privacy.coffee delete mode 100644 app/assets/javascripts/app/views/network.jst.eco delete mode 100644 app/controllers/network_controller.rb delete mode 100644 app/controllers/sessions/collection_network.rb delete mode 100644 app/models/network.rb delete mode 100644 config/routes/network.rb delete mode 100644 db/migrate/20120101000020_create_network.rb create mode 100644 db/migrate/20170912123300_remove_network.rb delete mode 100644 db/seeds/networks.rb diff --git a/app/assets/javascripts/app/controllers/network.coffee b/app/assets/javascripts/app/controllers/network.coffee deleted file mode 100644 index e0c165635..000000000 --- a/app/assets/javascripts/app/controllers/network.coffee +++ /dev/null @@ -1,67 +0,0 @@ -class Index extends App.ControllerContent - events: - 'click [data-type=network-new]': 'network_new' - 'click [data-type=network-edit]': 'network_edit' - 'click [data-type=network-destroy]': 'network_destroy' - 'click [data-type=network-category-new]': 'network_category_new' - 'click [data-type=network-category-edit]': 'network_category_edit' - 'click [data-type=network-category-destroy]': 'network_category_destroy' - - constructor: -> - super - - # set title - @title 'Network' - @render() - @navupdate '#network' - - render: -> - networks = App.Network.all() - network_categories = App.NetworkCategory.all() - for network in networks - @log 'notice', network for network in networks - - for network_category in network_categories - @log 'notice', network_category - - @html App.view('network')( - networks: App.Network.all(), - ) - - network_new: (e) -> - e.preventDefault() - new App.ControllerGenericNewWindow( - pageData: { - object: 'Network', - }, - genericObject: App.Network, - success: => - @render() - ) - - network_edit: (e) -> - e.preventDefault() - @id = $(e.target).parents('[data-id]').data('id') - new App.ControllerGenericEditWindow( - id: @id, - pageData: { - object: 'Network', - }, - genericObject: App.Network, - success: => - @render() - ) - - network_destroy: (e) -> - e.preventDefault() - id = $(e.target).parents('[data-id]').data('id') - item = App.Network.find(id) - item.destroy() if confirm('Sure?') - @render() - -App.Config.set( 'network', Index, 'Routes' ) - -#App.Config.set( 'Network', { prio: 1500, parent: '', name: 'Networking', target: '#network', role: ['Anybody', 'Customer', 'Agent'] }, 'NavBar' ), 'NavBar' ) -#App.Config.set( '', { prio: 1600, parent: '', name: 'anybody+agent', target: '#aa', role: ['Anybody', 'Agent'] } -#App.Config.set( '', { prio: 1600, parent: '', name: 'Anybody', target: '#anybody', role: ['Anybody'] } - diff --git a/app/assets/javascripts/app/models/network.coffee b/app/assets/javascripts/app/models/network.coffee deleted file mode 100644 index 17140fdb9..000000000 --- a/app/assets/javascripts/app/models/network.coffee +++ /dev/null @@ -1,9 +0,0 @@ -class App.Network extends App.Model - @configure 'Network', 'name', 'note', 'active', 'updated_at' - @extend Spine.Model.Ajax - @configure_attributes = [ - { name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 100, null: false }, - { name: 'note', display: 'Note', note: 'Notes are visible to agents only, never to customers.', tag: 'textarea', limit: 250, null: true }, - { name: 'updated_at', display: 'Updated', tag: 'datetime', readonly: 1 }, - { name: 'active', display: 'Active', tag: 'active', default: true }, - ] diff --git a/app/assets/javascripts/app/models/network_category.coffee b/app/assets/javascripts/app/models/network_category.coffee deleted file mode 100644 index 2fef16be8..000000000 --- a/app/assets/javascripts/app/models/network_category.coffee +++ /dev/null @@ -1,3 +0,0 @@ -class App.NetworkCategory extends App.Model - @configure 'NetworkCategory', 'name', 'network_id', 'network_category_type_id', 'network_privacy_id', 'note', 'allow_comments', 'active', 'updated_at' - @extend Spine.Model.Ajax diff --git a/app/assets/javascripts/app/models/network_category_type.coffee b/app/assets/javascripts/app/models/network_category_type.coffee deleted file mode 100644 index 12ba541a6..000000000 --- a/app/assets/javascripts/app/models/network_category_type.coffee +++ /dev/null @@ -1,3 +0,0 @@ -class App.NetworkCategoryType extends App.Model - @configure 'NetworkCategoryType', 'name', 'note', 'active', 'updated_at' - @extend Spine.Model.Ajax diff --git a/app/assets/javascripts/app/models/network_privacy.coffee b/app/assets/javascripts/app/models/network_privacy.coffee deleted file mode 100644 index 1bf9a3590..000000000 --- a/app/assets/javascripts/app/models/network_privacy.coffee +++ /dev/null @@ -1,3 +0,0 @@ -class App.NetworkPrivacy extends App.Model - @configure 'NetworkPrivacy', 'name', 'key', 'updated_at' - @extend Spine.Model.Ajax diff --git a/app/assets/javascripts/app/views/network.jst.eco b/app/assets/javascripts/app/views/network.jst.eco deleted file mode 100644 index fb1ee677b..000000000 --- a/app/assets/javascripts/app/views/network.jst.eco +++ /dev/null @@ -1,84 +0,0 @@ - - -
-
- -<% for network in @networks: %> -
-
-

<%= network.name %> <%= network.note %>

edit | delete | new category -
-
-

Announcements

- edit | delete - -
-
-

Questions

- -
-
-
-
-

Ideas

- -
-
-

Bugs

- -
-
-
-
-<% end %> - -
-
- -
-
-

Actions

- -
-
- -
-
-

Activity Stream

-
    -
  • New XXX
  • -
  • New XXX
  • -
  • New XXX
  • -
  • New XXX
  • -
-
-
- -
-
diff --git a/app/controllers/network_controller.rb b/app/controllers/network_controller.rb deleted file mode 100644 index f257eb59f..000000000 --- a/app/controllers/network_controller.rb +++ /dev/null @@ -1,87 +0,0 @@ -# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ - -class NetworksController < ApplicationController - prepend_before_action :authentication_check - - # GET /networks - # GET /networks.json - def index - @networks = Network.all - - respond_to do |format| - format.html # index.html.erb - format.json { render json: @networks } - end - end - - # GET /networks/1 - # GET /networks/1.json - def show - @network = Network.find(params[:id]) - - respond_to do |format| - format.html # show.html.erb - format.json { render json: @network } - end - end - - # GET /networks/new - # GET /networks/new.json - def new - @network = Network.new - - respond_to do |format| - format.html # new.html.erb - format.json { render json: @network } - end - end - - # GET /networks/1/edit - def edit - @network = Network.find(params[:id]) - end - - # POST /networks - # POST /networks.json - def create - @network = Network.new(params[:network]) - - respond_to do |format| - if @network.save - format.html { redirect_to @network, notice: 'Network was successfully created.' } - format.json { render json: @network, status: :created } - else - format.html { render action: 'new' } - format.json { render json: @network.errors, status: :unprocessable_entity } - end - end - end - - # PUT /networks/1 - # PUT /networks/1.json - def update - @network = Network.find(params[:id]) - - respond_to do |format| - if @network.update!(params[:network]) - format.html { redirect_to @network, notice: 'Network was successfully updated.' } - format.json { render json: @network, status: :ok } - else - format.html { render action: 'edit' } - format.json { render json: @network.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /networks/1 - # DELETE /networks/1.json - def destroy - @network = Network.find(params[:id]) - @network.destroy - - respond_to do |format| - format.html { redirect_to networks_url } - format.json { head :ok } - end - end -end diff --git a/app/controllers/sessions/collection_network.rb b/app/controllers/sessions/collection_network.rb deleted file mode 100644 index 6ac868b64..000000000 --- a/app/controllers/sessions/collection_network.rb +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ - -module ExtraCollection - def session( collections, assets, _user ) - - collections[ Network.to_app_model ] = Network.all - collections[ Network::Category.to_app_model ] = Network::Category.all - collections[ Network::Category::Type.to_app_model ] = Network::Category::Type.all - collections[ Network::Privacy.to_app_model ] = Network::Privacy.all - [collections, assets] - end - - module_function :session -end diff --git a/app/models/network.rb b/app/models/network.rb deleted file mode 100644 index e1d054f95..000000000 --- a/app/models/network.rb +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ - -class Network < ApplicationModel - # belongs_to :group - # belongs_to :state, :class_name => 'Ticket::State' - # belongs_to :priority, :class_name => 'Ticket::Priority' - - class Category < ApplicationModel - self.table_name = 'network_categories' - - class Type < ApplicationModel - end - - class Subscription < ApplicationModel - end - end - - class Item < ApplicationModel - class Comment < ApplicationModel - end - - class Plus < ApplicationModel - self.table_name = 'network_item_plus' - end - - class Subscription < ApplicationModel - end - end - - class Privacy < ApplicationModel - self.table_name = 'network_privacies' - end -end diff --git a/config/routes/network.rb b/config/routes/network.rb deleted file mode 100644 index f3b6ecd7f..000000000 --- a/config/routes/network.rb +++ /dev/null @@ -1,11 +0,0 @@ -Zammad::Application.routes.draw do - api_path = Rails.configuration.api_path - - # networkss - match api_path + '/networks', to: 'networks#index', via: :get - match api_path + '/networks/:id', to: 'networks#show', via: :get - match api_path + '/networks', to: 'networks#create', via: :post - match api_path + '/networks/:id', to: 'networks#update', via: :put - match api_path + '/networks/:id', to: 'networks#destroy', via: :delete - -end diff --git a/db/migrate/20120101000020_create_network.rb b/db/migrate/20120101000020_create_network.rb deleted file mode 100644 index aaa1fde0d..000000000 --- a/db/migrate/20120101000020_create_network.rb +++ /dev/null @@ -1,108 +0,0 @@ -class CreateNetwork < ActiveRecord::Migration[4.2] - def up - create_table :networks do |t| - t.column :name, :string, limit: 100, null: false - t.column :note, :string, limit: 250, null: true - t.column :active, :boolean, null: false, default: true - t.column :updated_by_id, :integer, null: false - t.column :created_by_id, :integer, null: false - t.timestamps limit: 3, null: false - end - add_index :networks, [:name], unique: true - - create_table :network_category_types do |t| - t.column :name, :string, limit: 100, null: false - t.column :note, :string, limit: 250, null: true - t.column :active, :boolean, null: false, default: true - t.column :updated_by_id, :integer, null: false - t.column :created_by_id, :integer, null: false - t.timestamps limit: 3, null: false - end - add_index :network_category_types, [:name], unique: true - - create_table :network_privacies do |t| - t.column :name, :string, limit: 100, null: false - t.column :key, :string, limit: 250, null: false - t.column :updated_by_id, :integer, null: false - t.column :created_by_id, :integer, null: false - t.timestamps limit: 3, null: false - end - add_index :network_privacies, [:name], unique: true - - create_table :network_categories do |t| - t.references :network_category_type, null: false - t.references :network_privacy, null: false - t.references :network, null: false - t.column :name, :string, limit: 200, null: false - t.column :note, :string, limit: 250, null: true - t.column :allow_comments, :boolean, null: false, default: true - t.column :active, :boolean, null: false, default: true - t.column :updated_by_id, :integer, null: false - t.column :created_by_id, :integer, null: false - t.timestamps limit: 3, null: false - end - add_index :network_categories, [:network_id] - - create_table :network_categories_moderator_users, id: false do |t| - t.integer :user_id - t.integer :network_category_id - end - - create_table :network_items do |t| - t.references :network_category, null: false - t.column :title, :string, limit: 200, null: false - t.column :body, :string, limit: 20_000, null: false - t.column :updated_by_id, :integer, null: false - t.column :created_by_id, :integer, null: false - t.timestamps null: false - end - add_index :network_items, [:network_category_id] - - create_table :network_item_comments do |t| - t.references :network_item, null: false - t.column :body, :string, limit: 20_000, null: false - t.column :updated_by_id, :integer, null: false - t.column :created_by_id, :integer, null: false - t.timestamps limit: 3, null: false - end - add_index :network_item_comments, [:network_item_id] - - create_table :network_item_plus do |t| - t.references :network_item, null: false - t.column :updated_by_id, :integer, null: false - t.column :created_by_id, :integer, null: false - t.timestamps limit: 3, null: false - end - add_index :network_item_plus, [:network_item_id, :created_by_id], unique: true - - create_table :network_category_subscriptions do |t| - t.references :network_categories, null: false - t.column :updated_by_id, :integer, null: false - t.column :created_by_id, :integer, null: false - t.timestamps limit: 3, null: false - end - add_index :network_category_subscriptions, [:network_categories_id, :created_by_id], unique: true, name: 'index_network_category_subscriptions_on_network_c_i_and_c' - - create_table :network_item_subscriptions do |t| - t.references :network_item, null: false - t.column :updated_by_id, :integer, null: false - t.column :created_by_id, :integer, null: false - t.timestamps limit: 3, null: false - end - add_index :network_item_subscriptions, [:network_item_id, :created_by_id], unique: true, name: 'index_network_item_subscriptions_on_item_id_and_created_by_id' - - end - - def down - drop_table :network_item_subscriptions - drop_table :network_category_subscriptions - drop_table :network_categories_moderator_users - drop_table :network_item_plus - drop_table :network_item_comments - drop_table :network_items - drop_table :network_categories - drop_table :network_privacies - drop_table :network_category_types - drop_table :networks - end -end diff --git a/db/migrate/20170912123300_remove_network.rb b/db/migrate/20170912123300_remove_network.rb new file mode 100644 index 000000000..1671760f2 --- /dev/null +++ b/db/migrate/20170912123300_remove_network.rb @@ -0,0 +1,18 @@ +class RemoveNetwork < ActiveRecord::Migration + + # rewinds db/migrate/20120101000020_create_network.rb + def change + return if !ActiveRecord::Base.connection.table_exists? 'networks' + + drop_table :networks + drop_table :network_category_types + drop_table :network_privacies + drop_table :network_categories + drop_table :network_categories_moderator_users + drop_table :network_items + drop_table :network_item_comments + drop_table :network_item_plus + drop_table :network_category_subscriptions + drop_table :network_item_subscriptions + end +end diff --git a/db/seeds.rb b/db/seeds.rb index 885aa4407..2623896cc 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -13,7 +13,7 @@ Cache.clear # this is the __ordered__ list of seed files # extend only if needed - try to add your changes # to the matching one of the existing files -seeds = %w(settings user_nr_1 signatures roles permissions groups links ticket_state_types ticket_states ticket_priorities ticket_article_types ticket_article_senders macros community_user_resources overviews channels report_profiles chats networks object_manager_attributes schedulers triggers karma_activities) +seeds = %w(settings user_nr_1 signatures roles permissions groups links ticket_state_types ticket_states ticket_priorities ticket_article_types ticket_article_senders macros community_user_resources overviews channels report_profiles chats object_manager_attributes schedulers triggers karma_activities) # loop and require all seedfiles # files will get executed automatically diff --git a/db/seeds/networks.rb b/db/seeds/networks.rb deleted file mode 100644 index 4da71d606..000000000 --- a/db/seeds/networks.rb +++ /dev/null @@ -1,100 +0,0 @@ -network = Network.create_if_not_exists( - id: 1, - name: 'base', -) - -Network::Category::Type.create_if_not_exists( - id: 1, - name: 'Announcement', -) -Network::Category::Type.create_if_not_exists( - id: 2, - name: 'Idea', -) -Network::Category::Type.create_if_not_exists( - id: 3, - name: 'Question', -) -Network::Category::Type.create_if_not_exists( - id: 4, - name: 'Bug Report', -) - -Network::Privacy.create_if_not_exists( - id: 1, - name: 'logged in', - key: 'loggedIn', -) -Network::Privacy.create_if_not_exists( - id: 2, - name: 'logged in and moderator', - key: 'loggedInModerator', -) -Network::Category.create_if_not_exists( - id: 1, - name: 'Announcements', - network_id: network.id, - network_category_type_id: Network::Category::Type.find_by(name: 'Announcement').id, - network_privacy_id: Network::Privacy.find_by(name: 'logged in and moderator').id, - allow_comments: true, -) -Network::Category.create_if_not_exists( - id: 2, - name: 'Questions', - network_id: network.id, - allow_comments: true, - network_category_type_id: Network::Category::Type.find_by(name: 'Question').id, - network_privacy_id: Network::Privacy.find_by(name: 'logged in').id, -) -Network::Category.create_if_not_exists( - id: 3, - name: 'Ideas', - network_id: network.id, - network_category_type_id: Network::Category::Type.find_by(name: 'Idea').id, - network_privacy_id: Network::Privacy.find_by(name: 'logged in').id, - allow_comments: true, -) -Network::Category.create_if_not_exists( - id: 4, - name: 'Bug Reports', - network_id: network.id, - network_category_type_id: Network::Category::Type.find_by(name: 'Bug Report').id, - network_privacy_id: Network::Privacy.find_by(name: 'logged in').id, - allow_comments: true, -) -item = Network::Item.create( - title: 'Example Announcement', - body: 'Some announcement....', - network_category_id: Network::Category.find_by(name: 'Announcements').id, -) -Network::Item::Comment.create( - network_item_id: item.id, - body: 'Some comment....', -) -item = Network::Item.create( - title: 'Example Question?', - body: 'Some questions....', - network_category_id: Network::Category.find_by(name: 'Questions').id, -) -Network::Item::Comment.create( - network_item_id: item.id, - body: 'Some comment....', -) -item = Network::Item.create( - title: 'Example Idea', - body: 'Some idea....', - network_category_id: Network::Category.find_by(name: 'Ideas').id, -) -Network::Item::Comment.create( - network_item_id: item.id, - body: 'Some comment....', -) -item = Network::Item.create( - title: 'Example Bug Report', - body: 'Some bug....', - network_category_id: Network::Category.find_by(name: 'Bug Reports').id, -) -Network::Item::Comment.create( - network_item_id: item.id, - body: 'Some comment....', -)