marty 10.0.3 → 11.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 360af94e92c74e7d1102352352fb0b412fb286028fd250b388532c48abb197f4
4
- data.tar.gz: 848685b6765630af1acdae54e6667ea995eee94d86ec36e0103313054df80140
3
+ metadata.gz: 119afa3c55c47a985cce5d53a9868f605e2fe401f90bd66bcf3465b03eaf8c5d
4
+ data.tar.gz: 83dfb56e30a009281111f825a05d603fef30830cf3c67e69c9e0399124d7e5a6
5
5
  SHA512:
6
- metadata.gz: d85a3910d4654ea5ee18a330b22c1bc23cef9dab6c6e745ff4fbb5b70a0a06a29b46b81b426adb3bbe51c3b2ccedc81264352beacc5b9161a2f32f23c92eed7a
7
- data.tar.gz: bd061cae990b2b935beac03df951065a405834c5d3757e641f557a4d1170bd9a9b3217cdd89267b262bb906a184202c7318a39eb3d8deb198ea22274ec3b43e2
6
+ metadata.gz: 1dfadeffa2456aa43340ba6a6848d78dcf8f938e7e500b78a262c9ae5886145884921ef58c08c9e8edc5451a01d0d21e1eabbd37a175065f988c402f63af8e11
7
+ data.tar.gz: 35e5a24aa4475cd027cc2111f64fba44510aeac35040ea0d13e84f64bbc6f4e3df45120ec9101499cf13c9b1676036a9dcd6e3f8a6b4fb58416f6311091a9ea0
@@ -73,6 +73,9 @@ Rails/DynamicFindBy:
73
73
  - 'spec/features/**/*'
74
74
  - 'spec/support/**/*'
75
75
 
76
+ Style/NumericPredicate:
77
+ Enabled: false
78
+
76
79
  Rails/ApplicationRecord:
77
80
  Enabled: false
78
81
 
@@ -81,3 +84,6 @@ Rails/ApplicationJob:
81
84
 
82
85
  Rails/ApplicationController:
83
86
  Enabled: false
87
+
88
+ Rails/IndexWith:
89
+ Enabled: false
@@ -256,13 +256,11 @@ class Marty::BaseRuleView < Marty::McflyGridPanel
256
256
  [
257
257
  jsonb_field(
258
258
  :results,
259
- {
260
- getter: jsonb_simple_getter(:results),
261
- setter: jsonb_simple_setter(:results),
262
- min_height: 150,
263
- height: nil, # must be nil to allow the field to resize automatically
264
- grow: true,
265
- }
259
+ getter: jsonb_simple_getter(:results),
260
+ setter: jsonb_simple_setter(:results),
261
+ min_height: 150,
262
+ height: nil, # must be nil to allow the field to resize automatically
263
+ grow: true,
266
264
  )
267
265
  ]
268
266
  end
@@ -8,14 +8,14 @@ require 'marty/config_view'
8
8
  require 'marty/data_grid_view'
9
9
  require 'marty/data_grid_user_view'
10
10
  require 'marty/import_type_view'
11
- require 'marty/new_posting_window'
12
11
  require 'marty/notifications/config_view'
13
12
  require 'marty/notifications/deliveries_view'
14
- require 'marty/posting_window'
13
+ require 'marty/postings/new_window'
14
+ require 'marty/postings/window'
15
15
  require 'marty/promise_view'
16
16
  require 'marty/reporting'
17
17
  require 'marty/scripting'
18
- require 'marty/user_view'
18
+ require 'marty/users/user_view'
19
19
 
20
20
  class Marty::MainAuthApp < Marty::AuthApp
21
21
  extend ::Marty::Permissions
@@ -27,7 +27,7 @@ class Marty::MainAuthApp < Marty::AuthApp
27
27
 
28
28
  # set of posting types user is allowed to post with
29
29
  def self.has_posting_perm?
30
- Marty::NewPostingForm.has_any_perm?
30
+ Marty::Postings::NewForm.has_any_perm?
31
31
  end
32
32
 
33
33
  def self.has_scripting_perm?
@@ -507,6 +507,7 @@ class Marty::MainAuthApp < Marty::AuthApp
507
507
 
508
508
  component :new_posting_window do |c|
509
509
  c.disabled = Marty::Util.warped? || !self.class.has_posting_perm?
510
+ c.klass = ::Marty::Postings::NewWindow
510
511
  end
511
512
 
512
513
  component :notifications_config_view do |c|
@@ -517,7 +518,9 @@ class Marty::MainAuthApp < Marty::AuthApp
517
518
  c.klass = ::Marty::Notifications::DeliveriesView
518
519
  end
519
520
 
520
- component :posting_window
521
+ component :posting_window do |c|
522
+ c.klass = ::Marty::Postings::Window
523
+ end
521
524
 
522
525
  component :promise_view do |c|
523
526
  c.klass = Marty::PromiseView
@@ -537,7 +540,9 @@ class Marty::MainAuthApp < Marty::AuthApp
537
540
  c.allow_edit = self.class.has_scripting_perm?
538
541
  end
539
542
 
540
- component :user_view
543
+ component :user_view do |c|
544
+ c.klass = ::Marty::Users::UserView
545
+ end
541
546
 
542
547
  endpoint :reload_scripts do |_params|
543
548
  Marty::Script.load_scripts
@@ -0,0 +1,80 @@
1
+ module Marty
2
+ module Postings
3
+ class Grid < Marty::Grid
4
+ has_marty_permissions read: :any,
5
+ delete: :any # delete is hijacked for a select
6
+
7
+ def configure(c)
8
+ super
9
+
10
+ c.header = false
11
+ c.model = 'Marty::Posting'
12
+ c.attributes = [:name, :created_dt, :user__name, :comment]
13
+ c.multi_select = false
14
+ c.store_config.merge!(sorters: [{ property: :created_dt, direction: 'DESC' }],
15
+ page_size: 12)
16
+ end
17
+
18
+ client_class do |c|
19
+ c.include :grid
20
+ end
21
+
22
+ # hijacking delete button
23
+ action :delete do |a|
24
+ a.text = 'Select'
25
+ a.tooltip = 'Select'
26
+ a.icon_cls = 'fa fa-clock glyph'
27
+ a.disabled = true
28
+ end
29
+
30
+ def default_bbar
31
+ [:delete, :detail]
32
+ end
33
+
34
+ action :detail do |a|
35
+ a.text = 'Detail'
36
+ a.icon_cls = 'fa fa-th-large glyph'
37
+ a.handler = :detail
38
+ a.disabled = true
39
+ end
40
+
41
+ endpoint :detail do |params|
42
+ record_id = params[:record_id]
43
+
44
+ # Prepare an HTML popup with session details such that the
45
+ # contents can be easily pasted into a spreadsheet.
46
+
47
+ pt = Marty::Posting.find_by(id: record_id)
48
+
49
+ dt = pt.created_dt.to_s == 'Infinity' ? '---' :
50
+ pt.created_dt.strftime('%Y-%m-%d %I:%M %p')
51
+
52
+ html =
53
+ "<b>Name:</b>\t#{pt.name}<br/>" \
54
+ "<b>Date/Time:</b>\t#{dt}<br/>" \
55
+ "<b>User:</b>\t#{pt.user.name}<br/>" \
56
+ "<b>Comment:</b>\t#{pt.comment}"
57
+
58
+ client.netzke_show_detail html
59
+ end
60
+
61
+ attribute :name do |c|
62
+ c.flex = 1
63
+ end
64
+
65
+ attribute :created_dt do |c|
66
+ c.text = 'Date/Time'
67
+ c.format = 'Y-m-d H:i'
68
+ c.hidden = true
69
+ end
70
+
71
+ attribute :user__name do |c|
72
+ c.width = 100
73
+ end
74
+
75
+ attribute :comment do |c|
76
+ c.width = 100
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,52 @@
1
+ require 'marty/postings/summary_grid'
2
+
3
+ module Marty
4
+ module Postings
5
+ class NewForm < Marty::Form
6
+ extend ::Marty::Permissions
7
+
8
+ # override this to set permissions for posting types
9
+ has_marty_permissions read: :any
10
+
11
+ client_class do |c|
12
+ c.include :new_form
13
+ end
14
+
15
+ action :apply do |a|
16
+ a.text = I18n.t('create_posting')
17
+ a.tooltip = I18n.t('create_posting')
18
+ a.icon_cls = 'fa fa-clock glyph'
19
+ end
20
+
21
+ ######################################################################
22
+
23
+ endpoint :submit do |params|
24
+ res = super(params)
25
+ client.close_me
26
+ res
27
+ end
28
+
29
+ def configure(c)
30
+ super
31
+
32
+ c.model = 'Marty::Posting'
33
+ c.items = [
34
+ {
35
+ name: :posting_type__name,
36
+ scope: lambda { |r|
37
+ r.where(name: Marty::Postings::NewForm.can_perform_actions)
38
+ },
39
+ },
40
+ :comment,
41
+ :summary_grid
42
+ ]
43
+ end
44
+
45
+ component :summary_grid do |c|
46
+ c.klass = Marty::Postings::SummaryGrid
47
+ c.data_store = { auto_load: false }
48
+ c.selected_posting_type = client_config[:selected_posting_type]
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,33 @@
1
+ ({
2
+ closeMe() {
3
+ // assume we're embedded in a window
4
+ this.netzkeGetParentComponent().close();
5
+ },
6
+
7
+ initComponent() {
8
+ this.callParent();
9
+
10
+ const postingType = this.getForm().findField("posting_type__name");
11
+ const me = this;
12
+
13
+ me.serverConfig.selected_posting_type = null;
14
+ // For some reason initComponent gets called twice
15
+ // So this workaround prevents from adding the listener second time
16
+ if (this.hasPostingTypeChangeListener) {
17
+ return;
18
+ }
19
+
20
+ postingType.on("change", function(self, record) {
21
+ if (record instanceof Array) {
22
+ record = record[0];
23
+ }
24
+
25
+ me.serverConfig.selected_posting_type = record;
26
+ me.getComponent("summary_grid")
27
+ .getStore()
28
+ .load();
29
+ });
30
+
31
+ this.hasPostingTypeChangeListener = true;
32
+ }
33
+ });
@@ -0,0 +1,23 @@
1
+ require 'marty/postings/new_form'
2
+
3
+ module Marty
4
+ module Postings
5
+ class NewWindow < Netzke::Window::Base
6
+ def configure(c)
7
+ super
8
+
9
+ c.title = I18n.t('new_posting')
10
+ c.modal = true
11
+ c.items = [:new_posting_form]
12
+ c.lazy_loading = true
13
+ c.width = 800
14
+ c.height = 550
15
+ end
16
+
17
+ component :new_posting_form do |c|
18
+ c.header = false
19
+ c.klass = Marty::Postings::NewForm
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,100 @@
1
+ module Marty
2
+ module Postings
3
+ class SummaryGrid < Marty::Grid
4
+ def configure(c)
5
+ super
6
+
7
+ c.model = 'Marty::Log' # Hack, since grid requires a model to be set
8
+ c.multi_select = false
9
+ c.read_only = true
10
+ c.attributes ||= [:klass, :created, :updated, :deleted]
11
+ c.title ||= I18n.t('summary', default: 'Summary')
12
+ c.paging = false
13
+ c.min_height = 400
14
+ c.height = 400
15
+ c.bbar = nil
16
+ end
17
+
18
+ client_styles do |c|
19
+ c.require :summary_grid
20
+ end
21
+
22
+ attribute :klass do |c|
23
+ c.min_width = 300
24
+ c.sortable = true
25
+ end
26
+
27
+ column :created do |c|
28
+ c.sortable = true
29
+ end
30
+
31
+ column :updated do |c|
32
+ c.sortable = true
33
+ end
34
+
35
+ column :deleted do |c|
36
+ c.sortable = true
37
+ end
38
+
39
+ def get_records(params)
40
+ return [] if config[:selected_posting_type].blank?
41
+ return [] if config[:selected_posting_type].to_i.negative?
42
+
43
+ last_posting = Marty::Posting.where(
44
+ posting_type_id: config[:selected_posting_type]
45
+ ).where.not(created_dt: 'infinity').order(:created_dt).last
46
+
47
+ start_dt = last_posting&.created_dt || 1.year.ago
48
+ end_dt = Time.zone.now
49
+
50
+ posting_type = Marty::PostingType.find(config[:selected_posting_type])
51
+
52
+ summary_records = class_list(posting_type).map do |klass|
53
+ summary = Marty::DataChange.change_summary(start_dt, end_dt, klass)
54
+ OpenStruct.new(summary.merge('klass' => klass))
55
+ end
56
+
57
+ records_with_changes = summary_records.select do |record|
58
+ record.created > 0 || record.updated > 0 || record.deleted > 0
59
+ end
60
+
61
+ total_summary = OpenStruct.new(
62
+ klass: 'Total',
63
+ created: summary_records.sum(&:created),
64
+ updated: summary_records.sum(&:updated),
65
+ deleted: summary_records.sum(&:deleted)
66
+ )
67
+
68
+ [total_summary] + sort_records(params, records_with_changes)
69
+ end
70
+
71
+ def class_list(posting_type)
72
+ method_name = "class_list_#{posting_type.name}".downcase.to_sym
73
+
74
+ if Marty::DataChange.respond_to?(method_name)
75
+ Marty::DataChange.send(method_name)
76
+ else
77
+ Marty::DataChange.class_list
78
+ end
79
+ end
80
+
81
+ def sort_records(params, records)
82
+ return records if params['sorters'].blank?
83
+
84
+ sorting_attr = params.dig('sorters', 0, 'property').to_sym
85
+
86
+ sorted = records.sort_by(&:sorting_attr)
87
+ sorted = sorted.reverse if params.dig('sorters', 0, 'direction') != 'ASC'
88
+
89
+ sorted
90
+ end
91
+
92
+ def count_records(_params, _columns = [])
93
+ return 0 if config[:selected_posting_type].blank?
94
+ return 0 if config[:selected_posting_type].to_i.negative?
95
+
96
+ Marty::DataChange.class_list.size + 1
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,3 @@
1
+ .x-grid-row.bold .x-grid-td {
2
+ font-weight: bold;
3
+ }
@@ -0,0 +1,10 @@
1
+ ({
2
+ initComponent() {
3
+ this.viewConfig = {
4
+ getRowClass(r) {
5
+ return r.get("klass") === "Total" ? "bold" : "";
6
+ }
7
+ };
8
+ this.callParent();
9
+ }
10
+ });
@@ -0,0 +1,29 @@
1
+ require 'marty/postings/grid'
2
+
3
+ module Marty
4
+ module Postings
5
+ class Window < Netzke::Window::Base
6
+ def configure(c)
7
+ super
8
+
9
+ c.title = I18n.t('select_posting')
10
+ c.modal = true
11
+ c.items = [:posting_grid]
12
+ c.lazy_loading = true
13
+ c.width = 600
14
+ c.height = 350
15
+ end
16
+
17
+ component :posting_grid do |c|
18
+ c.klass = Marty::Postings::Grid
19
+ c.rows_per_page = 12
20
+ c.permissions = {
21
+ update: false,
22
+ delete: true, # hijacked for selection
23
+ create: false,
24
+ }
25
+ # c.bbar = []
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,5 +1,5 @@
1
1
  module Marty
2
- class Users
2
+ module Users
3
3
  class UserView < Marty::Grid
4
4
  has_marty_permissions create: [:admin, :user_manager],
5
5
  read: :any,
@@ -156,7 +156,8 @@ module Marty
156
156
  Marty::RoleType.to_nice_names(r.user_roles.map(&:role))
157
157
  end
158
158
 
159
- store = ::Marty::RoleType.to_nice_names(::Marty::RoleType.values.sort)
159
+ roles = Rails.application.config.marty.roles || ::Marty::RoleType.values
160
+ store = ::Marty::RoleType.to_nice_names(roles.sort)
160
161
 
161
162
  c.editor_config = {
162
163
  multi_select: true,
@@ -100,8 +100,8 @@ class Marty::DataGrid < Marty::Base
100
100
  validates_with DataGridValidator
101
101
  validates_with Marty::NameValidator, field: :name
102
102
 
103
- gen_mcfly_lookup :lookup, [:name], cache: true
104
- gen_mcfly_lookup :get_all, [], mode: nil
103
+ gen_mcfly_lookup :lookup, [:name], cache: true, to_hash: true
104
+ gen_mcfly_lookup :get_all, [], mode: nil, to_hash: true
105
105
 
106
106
  # FIXME: if the caller requests data as part of fields, there could
107
107
  # be memory concerns with caching since some data_grids have massive data
@@ -9,7 +9,7 @@ class Marty::Script < Marty::Base
9
9
 
10
10
  belongs_to :user, class_name: 'Marty::User'
11
11
 
12
- gen_mcfly_lookup :lookup, [:name], cache: true
12
+ gen_mcfly_lookup :lookup, [:name], cache: true, to_hash: true
13
13
 
14
14
  # find script by name/tag (not cached)
15
15
 
@@ -309,4 +309,9 @@ class Marty::DataChange
309
309
  res[fk] = arr unless arr.empty?
310
310
  end
311
311
  end
312
+
313
+ # Can be overriden in Marty apps
314
+ def self.class_list_base
315
+ class_list
316
+ end
312
317
  end
@@ -6,8 +6,16 @@ module Mcfly::Model
6
6
  end
7
7
 
8
8
  module ClassMethods
9
- def openstruct_if_necessary(q, private)
10
- !private && q.is_a?(ActiveRecord::Base) ? make_openstruct(q) : q
9
+ def openstruct_if_necessary(q, private_lookup)
10
+ return q if private_lookup
11
+ return q unless q.is_a?(ActiveRecord::Base)
12
+
13
+ warning = 'Mcfly::Model#openstruct_if_necessary is deprecated.' \
14
+ "Please use 'to_hash: true' or 'private: true' option instead"
15
+
16
+ Rails.logger.warn warning
17
+
18
+ make_openstruct(q)
11
19
  end
12
20
 
13
21
  def hash_if_necessary(q, to_hash)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Marty
4
- VERSION = '10.0.3'
4
+ VERSION = '11.0.0'
5
5
  end
@@ -0,0 +1,6 @@
1
+ require 'marty/postings/new_form'
2
+
3
+ Marty::Postings::NewForm
4
+
5
+ Marty::Postings::NewForm.has_marty_permissions(BASE: :admin)
6
+
@@ -17,7 +17,7 @@ feature 'Posting workflows', js: true do
17
17
  def monkey_patch_new_posting_form
18
18
  # presently, Gemini displays similar monkeypatching behavior.
19
19
  # consider coming up with a proper fix...
20
- Marty::NewPostingForm.has_marty_permissions(BASE: :admin)
20
+ Marty::Postings::NewForm.has_marty_permissions(BASE: :admin)
21
21
  end
22
22
 
23
23
  it 'create posting and select it' do
@@ -553,7 +553,7 @@ EOS
553
553
  end
554
554
 
555
555
  it 'should handle string typed data grids' do
556
- expect(Marty::DataGrid.lookup('infinity', 'G7').data_type).to eq 'string'
556
+ expect(Marty::DataGrid.lookup('infinity', 'G7')['data_type']).to eq 'string'
557
557
 
558
558
  res = lookup_grid_helper('infinity',
559
559
  'G7',
@@ -564,7 +564,7 @@ EOS
564
564
  end
565
565
 
566
566
  it 'should handle DataGrid typed data grids' do
567
- expect(Marty::DataGrid.lookup('infinity', 'G8').data_type).
567
+ expect(Marty::DataGrid.lookup('infinity', 'G8')['data_type']).
568
568
  to eq 'Marty::DataGrid'
569
569
  g1 = Marty::DataGrid.lookup('infinity', 'G1')
570
570
 
@@ -573,7 +573,7 @@ EOS
573
573
  end
574
574
 
575
575
  it 'should handle multi DataGrid lookups' do
576
- expect(Marty::DataGrid.lookup('infinity', 'G8').data_type).
576
+ expect(Marty::DataGrid.lookup('infinity', 'G8')['data_type']).
577
577
  to eq 'Marty::DataGrid'
578
578
 
579
579
  h = {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marty
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.0.3
4
+ version: 11.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arman Bostani
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2020-03-24 00:00:00.000000000 Z
17
+ date: 2020-03-31 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: actioncable
@@ -345,18 +345,21 @@ files:
345
345
  - app/components/marty/main_auth_app/client/main_auth_app.js
346
346
  - app/components/marty/mcfly_grid_panel.rb
347
347
  - app/components/marty/mcfly_grid_panel/client/mcfly_grid_panel.js
348
- - app/components/marty/new_posting_form.rb
349
- - app/components/marty/new_posting_form/client/new_posting_form.js
350
- - app/components/marty/new_posting_window.rb
351
348
  - app/components/marty/notifications/config_view.rb
352
349
  - app/components/marty/notifications/deliveries_view.rb
353
350
  - app/components/marty/notifications/grid_view.rb
354
351
  - app/components/marty/notifications/window.rb
355
352
  - app/components/marty/panel.rb
356
353
  - app/components/marty/panel/client/panel.js
357
- - app/components/marty/posting_grid.rb
358
- - app/components/marty/posting_grid/client/posting_grid.js
359
- - app/components/marty/posting_window.rb
354
+ - app/components/marty/postings/grid.rb
355
+ - app/components/marty/postings/grid/client/grid.js
356
+ - app/components/marty/postings/new_form.rb
357
+ - app/components/marty/postings/new_form/client/new_form.js
358
+ - app/components/marty/postings/new_window.rb
359
+ - app/components/marty/postings/summary_grid.rb
360
+ - app/components/marty/postings/summary_grid/client/summary_grid.css
361
+ - app/components/marty/postings/summary_grid/client/summary_grid.js
362
+ - app/components/marty/postings/window.rb
360
363
  - app/components/marty/promise_view.rb
361
364
  - app/components/marty/promise_view/client/promise_view.css
362
365
  - app/components/marty/promise_view/client/promise_view.js
@@ -380,7 +383,6 @@ files:
380
383
  - app/components/marty/tag_grid.rb
381
384
  - app/components/marty/tree.rb
382
385
  - app/components/marty/tree/client/tree.js
383
- - app/components/marty/user_view.rb
384
386
  - app/components/marty/users/user_view.rb
385
387
  - app/controllers/marty/application_controller.rb
386
388
  - app/controllers/marty/components_controller.rb
@@ -662,6 +664,7 @@ files:
662
664
  - spec/dummy/config/initializers/delayed_job.rb
663
665
  - spec/dummy/config/initializers/inflections.rb
664
666
  - spec/dummy/config/initializers/mime_types.rb
667
+ - spec/dummy/config/initializers/postings.rb
665
668
  - spec/dummy/config/initializers/secret_token.rb
666
669
  - spec/dummy/config/initializers/session_store.rb
667
670
  - spec/dummy/config/initializers/wrap_parameters.rb
@@ -1,41 +0,0 @@
1
- class Marty::NewPostingForm < Marty::Form
2
- extend ::Marty::Permissions
3
-
4
- # override this to set permissions for posting types
5
- has_marty_permissions read: :any
6
-
7
- client_class do |c|
8
- c.include :new_posting_form
9
- end
10
-
11
- action :apply do |a|
12
- a.text = I18n.t('create_posting')
13
- a.tooltip = I18n.t('create_posting')
14
- a.icon_cls = 'fa fa-clock glyph'
15
- end
16
-
17
- ######################################################################
18
-
19
- endpoint :submit do |params|
20
- res = super(params)
21
- client.close_me
22
- res
23
- end
24
-
25
- def configure(c)
26
- super
27
-
28
- c.model = 'Marty::Posting'
29
- c.items = [
30
- {
31
- name: :posting_type__name,
32
- scope: lambda { |r|
33
- r.where(name: Marty::NewPostingForm.can_perform_actions)
34
- },
35
- },
36
- :comment,
37
- ]
38
- end
39
- end
40
-
41
- NewPostingForm = Marty::NewPostingForm
@@ -1,6 +0,0 @@
1
- ({
2
- closeMe() {
3
- // assume we're embedded in a window
4
- this.netzkeGetParentComponent().close();
5
- }
6
- });
@@ -1,19 +0,0 @@
1
- require 'marty/new_posting_form'
2
-
3
- class Marty::NewPostingWindow < Netzke::Window::Base
4
- def configure(c)
5
- super
6
-
7
- c.title = I18n.t('new_posting')
8
- c.modal = true
9
- c.items = [:new_posting_form]
10
- c.layout = 'fit'
11
- c.lazy_loading = true
12
- end
13
-
14
- component :new_posting_form do |c|
15
- c.header = false
16
- end
17
- end
18
-
19
- NewPostingWindow = Marty::NewPostingWindow
@@ -1,78 +0,0 @@
1
- class Marty::PostingGrid < Marty::Grid
2
- has_marty_permissions read: :any,
3
- delete: :any # delete is hijacked for a select
4
-
5
- def configure(c)
6
- super
7
-
8
- c.header = false
9
- c.model = 'Marty::Posting'
10
- c.attributes = [:name, :created_dt, :user__name, :comment]
11
- c.multi_select = false
12
- c.store_config.merge!(sorters: [{ property: :created_dt, direction: 'DESC' }],
13
- page_size: 12)
14
- end
15
-
16
- client_class do |c|
17
- c.include :posting_grid
18
- end
19
-
20
- # hijacking delete button
21
- action :delete do |a|
22
- a.text = 'Select'
23
- a.tooltip = 'Select'
24
- a.icon_cls = 'fa fa-clock glyph'
25
- a.disabled = true
26
- end
27
-
28
- def default_bbar
29
- [:delete, :detail]
30
- end
31
-
32
- action :detail do |a|
33
- a.text = 'Detail'
34
- a.icon_cls = 'fa fa-th-large glyph'
35
- a.handler = :detail
36
- a.disabled = true
37
- end
38
-
39
- endpoint :detail do |params|
40
- record_id = params[:record_id]
41
-
42
- # Prepare an HTML popup with session details such that the
43
- # contents can be easily pasted into a spreadsheet.
44
-
45
- pt = Marty::Posting.find_by(id: record_id)
46
-
47
- dt = pt.created_dt.to_s == 'Infinity' ? '---' :
48
- pt.created_dt.strftime('%Y-%m-%d %I:%M %p')
49
-
50
- html =
51
- "<b>Name:</b>\t#{pt.name}<br/>" +
52
- "<b>Date/Time:</b>\t#{dt}<br/>" +
53
- "<b>User:</b>\t#{pt.user.name}<br/>" +
54
- "<b>Comment:</b>\t#{pt.comment}"
55
-
56
- client.netzke_show_detail html
57
- end
58
-
59
- attribute :name do |c|
60
- c.flex = 1
61
- end
62
-
63
- attribute :created_dt do |c|
64
- c.text = 'Date/Time'
65
- c.format = 'Y-m-d H:i'
66
- c.hidden = true
67
- end
68
-
69
- attribute :user__name do |c|
70
- c.width = 100
71
- end
72
-
73
- attribute :comment do |c|
74
- c.width = 100
75
- end
76
- end
77
-
78
- PostingGrid = Marty::PostingGrid
@@ -1,25 +0,0 @@
1
- class Marty::PostingWindow < Netzke::Window::Base
2
- def configure(c)
3
- super
4
-
5
- c.title = I18n.t('select_posting')
6
- c.modal = true
7
- c.items = [:posting_grid]
8
- c.lazy_loading = true
9
- c.width = 600
10
- c.height = 350
11
- end
12
-
13
- component :posting_grid do |c|
14
- c.klass = Marty::PostingGrid
15
- c.rows_per_page = 12
16
- c.permissions = {
17
- update: false,
18
- delete: true, # hijacked for selection
19
- create: false,
20
- }
21
- # c.bbar = []
22
- end
23
- end
24
-
25
- PostingWindow = Marty::PostingWindow
@@ -1,174 +0,0 @@
1
- module Marty; class UserView < Marty::Grid
2
- has_marty_permissions create: [:admin, :user_manager],
3
- read: :any,
4
- update: [:admin, :user_manager],
5
- delete: [:admin, :user_manager]
6
-
7
- # list of columns to be displayed in the grid view
8
- def self.user_columns
9
- [
10
- :login,
11
- :firstname,
12
- :lastname,
13
- :active,
14
- :user_roles,
15
- ]
16
- end
17
-
18
- def configure(c)
19
- super
20
-
21
- c.attributes ||= self.class.user_columns
22
- c.title ||= I18n.t('users', default: 'Users')
23
- c.model = 'Marty::User'
24
- c.editing = :in_form
25
- c.paging = :pagination
26
- c.multi_select = false
27
- c.store_config.merge!(sorters: [{ property: :login,
28
- direction: 'ASC',
29
- }]) if c.attributes.include?(:login)
30
- c.scope = ->(arel) { arel.includes(:user_roles) }
31
- end
32
-
33
- def self.set_roles(roles, user)
34
- roles = [] if roles.blank?
35
-
36
- roles = ::Marty::RoleType.from_nice_names(roles)
37
-
38
- roles_in_user = user.user_roles.map(&:role)
39
- roles_to_delete = roles_in_user - roles
40
- roles_to_add = roles - roles_in_user
41
-
42
- Marty::User.transaction do
43
- user.user_roles.where(role: roles_to_delete).map(&:destroy!)
44
-
45
- roles_to_add.each do |role|
46
- user.user_roles.create!(role: role)
47
- end
48
- end
49
- end
50
-
51
- def self.create_edit_user(data)
52
- # Creates initial place-holder user object and validate
53
- user = data['id'].nil? ? User.new : User.find(data['id'])
54
-
55
- user_columns.each do |c|
56
- user.send("#{c}=", data[c.to_s]) unless c == :user_roles
57
- end
58
-
59
- if user.valid?
60
- user.save
61
- set_roles(data['user_roles'], user)
62
- end
63
-
64
- user
65
- end
66
-
67
- # override the add_in_form and edit_in_form endpoint. User creation/update
68
- # needs to use the create_edit_user method.
69
-
70
- endpoint :add_window__add_form__submit do |params|
71
- data = ActiveSupport::JSON.decode(params[:data])
72
-
73
- data['id'] = nil
74
-
75
- unless self.class.can_perform_action?(:create)
76
- client.netzke_notify 'Permission Denied'
77
- return
78
- end
79
-
80
- user = self.class.create_edit_user(data)
81
- if user.valid?
82
- client.success = true
83
- client.netzke_on_submit_success
84
- else
85
- client.netzke_notify(model_adapter.errors_array(user).join("\n"))
86
- end
87
- end
88
-
89
- endpoint :edit_window__edit_form__submit do |params|
90
- data = ActiveSupport::JSON.decode(params[:data])
91
- unless self.class.can_perform_action?(:update)
92
- client.netzke_notify 'Permission Denied'
93
- return
94
- end
95
-
96
- user = self.class.create_edit_user(data)
97
- if user.valid?
98
- client.success = true
99
- client.netzke_on_submit_success
100
- else
101
- client.netzke_notify(model_adapter.errors_array(user).join("\n"))
102
- end
103
- end
104
-
105
- action :add do |a|
106
- super(a)
107
- a.text = I18n.t('user_grid.new')
108
- a.tooltip = I18n.t('user_grid.new')
109
- a.icon_cls = 'fa fa-user-plus glyph'
110
- end
111
-
112
- action :edit do |a|
113
- super(a)
114
- a.icon_cls = 'fa fa-user-cog glyph'
115
- end
116
-
117
- action :delete do |a|
118
- super(a)
119
- a.icon_cls = 'fa fa-user-minus glyph'
120
- end
121
-
122
- def default_context_menu
123
- []
124
- end
125
-
126
- attribute :login do |c|
127
- c.width = 100
128
- c.label = I18n.t('user_grid.login')
129
- end
130
-
131
- attribute :firstname do |c|
132
- c.width = 100
133
- c.label = I18n.t('user_grid.firstname')
134
- end
135
-
136
- attribute :lastname do |c|
137
- c.width = 100
138
- c.label = I18n.t('user_grid.lastname')
139
- end
140
-
141
- attribute :active do |c|
142
- c.width = 60
143
- c.label = I18n.t('user_grid.active')
144
- end
145
-
146
- attribute :user_roles do |c|
147
- c.width = 100
148
- c.flex = 1
149
- c.label = I18n.t('user_grid.roles')
150
- c.type = :string
151
-
152
- c.getter = lambda do |r|
153
- Marty::RoleType.to_nice_names(r.user_roles.map(&:role))
154
- end
155
-
156
- store = ::Marty::RoleType.to_nice_names(::Marty::RoleType.values.sort)
157
-
158
- c.editor_config = {
159
- multi_select: true,
160
- empty_text: I18n.t('user_grid.select_roles'),
161
- store: store,
162
- type: :string,
163
- xtype: :combo,
164
- }
165
- end
166
-
167
- attribute :created_dt do |c|
168
- c.label = I18n.t('user_grid.created_dt')
169
- c.format = 'Y-m-d H:i'
170
- c.read_only = true
171
- end
172
- end; end
173
-
174
- UserView = Marty::UserView