Class: Netzke::Communitypack::Workspace

Inherits:
Base
  • Object
show all
Defined in:
lib/netzke/communitypack/workspace.rb

Overview

A component that allows for dynamical loading/unloading of other Netzke components in tabs. Warning: This component may be not secure enough, as it allows loading any Netzke component at the request from the client (component class has been sent as a paremeter for the deliver_component endpoint). A more secure implementation would white-list the components to be loaded.

It can be manipulated by calling the loadInTab method, e.g.:

workspace.loadInTab("UserGrid", {newTab: true})
  • will load a UserGrid component from the server in a new tab.

Client-side methods:

loadInTab(componentClassName, options) - loads a component in a tab.

* +options+ is an object that may contain the following keys:
    * +newTab+ (boolean) - whether to load a component in a newly created tab (+true+), or in the active tab (+false+, default)
    * +config+ (object) - config for the loaded Netzke component

closeAllTabs - closes all open tabs

Configuration

Accepts the following options:

  • always_reload_first_tab (default false) - reload the first tab each time it gets activated

Instance Method Summary (collapse)

Instance Method Details

- (Object) components

Overriding this to allow for dynamically declared components



67
68
69
# File 'lib/netzke/communitypack/workspace.rb', line 67

def components
  super.merge(stored_tabs.inject({}){ |r,tab| r.merge(tab[:name].to_sym => tab.reverse_merge(:header => false, :border => false)) })
end

- (Object) configure(c)



36
37
38
39
# File 'lib/netzke/communitypack/workspace.rb', line 36

def configure(c)
  c.items = [:dashboard, *stored_tabs.map{|c| c[:component] = c[:name].to_sym}]
  super
end

- (Object) extend_item(item)



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/netzke/communitypack/workspace.rb', line 41

def extend_item(item)
  item = super
  i = get_item_index
  c = component_instance(item[:netzke_component])
  { layout: :fit,
    title: c.config.title,
    closable: i > 0,
    netzke_component_id: :cmp#{i}",
    items: i == 0 ? [item] : []
  }
end

- (Object) get_item_index



53
54
55
56
# File 'lib/netzke/communitypack/workspace.rb', line 53

def get_item_index
  @item_index ||= -1
  @item_index += 1
end

- (Object) stored_tabs

We store these in component_session atm. May as well be in persistent storage, depending on the requirements



113
114
115
# File 'lib/netzke/communitypack/workspace.rb', line 113

def stored_tabs
  @stored_tabs ||= state[:items] || []
end