cpee-model-management 1.2.10 → 1.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68469ced2c1473df13f7c78a6c99f14530c8c90470244257e3b56ab5d335221b
4
- data.tar.gz: f9dbc4eb3232432bbb0312b0e0291d268924e8fb92a4da8f65ffed35e24c8cdc
3
+ metadata.gz: 2bb00b27314793ffe013566706f36b90a9ec191e3af593e8abfa58f6f55759e1
4
+ data.tar.gz: ab0f9e2400707e9d04e2daf1bac18690c70ba392c44841561c45796417b5e2b1
5
5
  SHA512:
6
- metadata.gz: 98c607a4c484fc411d1300a26204fa6185c6f6c3a6a6c867edb1de45cd67011ea8ac0ca53ed3713f885043674038b7e09a3d4616f9a5f6392a67bc475e81d20f
7
- data.tar.gz: 6c5afad5a7fb3d2e8a2ad16f2ad112bdb0d8fe560c73b931645d945d4e7e0cb06ed59c37c2249f37f61e96ea77abd10fa1f50fcef6047bc2115c343bad1356bc
6
+ metadata.gz: a1f768b269311a352ac9d4ea6062d6d01b46d5cc826f89e6f15584f98214fcb2272f56e630a95d3f228257762e25dc0cdf8999f630055175c2271f24354aefd6
7
+ data.tar.gz: 8401e9a5861ad2535bf9b096be1806062c465baa161d992a3bb8ec0cf77e1d822474ef18b25b25ed958622abd96f837c0a77efee1a81045bf66ab98520a05ec9
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cpee-model-management"
3
- s.version = "1.2.10"
3
+ s.version = "1.2.11"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.license = "GPL-3.0-or-later"
6
6
  s.summary = "(Lifecycle) manage your process models in a directory or git repo."
@@ -27,6 +27,7 @@ require 'shellwords'
27
27
  require 'securerandom'
28
28
  require 'cpee/redis'
29
29
  require 'digest/sha1'
30
+ require 'open3'
30
31
 
31
32
  module CPEE
32
33
  module ModelManagement
@@ -39,7 +40,7 @@ module CPEE
39
40
  p1 = Pathname.new(File.dirname(old))
40
41
  p2 = Pathname.new(File.dirname(new))
41
42
  told = File.basename(old)
42
- tnew = File.join(p1.relative_path_from(p1).to_s,File.basename(new))
43
+ tnew = File.join(p2.relative_path_from(p1).to_s,File.basename(new))
43
44
  `git -c user.name='Christine Ashcreek' -c user.email=dev@null.com -c push.default=simple mv "#{told}" "#{tnew}" 2>/dev/null`
44
45
  `git -c user.name='Christine Ashcreek' -c user.email=dev@null.com -c push.default=simple rm -rf "#{told + '.active'}" 2>/dev/null`
45
46
  `git -c user.name='Christine Ashcreek' -c user.email=dev@null.com -c push.default=simple rm -rf "#{told + '.active-uuid'}" 2>/dev/null`
@@ -102,6 +103,15 @@ module CPEE
102
103
  File.delete(fname + '.active-uuid') rescue nil
103
104
  end
104
105
 
106
+ def self::git_init(models) #{{{
107
+ _, status = Open3.capture2e('git', 'rev-parse', '--is-inside-work-tree', chdir: models)
108
+ return if status.success?
109
+ Open3.capture2e('git', 'init', chdir: models)
110
+ Open3.capture2e('git', 'add', '-A', chdir: models)
111
+ Open3.capture2e('git', '-c', 'user.name=Christine Ashcreek', '-c', 'user.email=dev@null.com', 'commit', '-m', 'initial', chdir: models)
112
+ puts "➡ Models directory #{models} is now a git repository"
113
+ end #}}}
114
+
105
115
  def self::git_dir(models,file)
106
116
  return nil if file.nil?
107
117
  cdir = Dir.pwd
@@ -225,6 +235,50 @@ module CPEE
225
235
  Riddl::Parameter::Complex.new('list','application/json',JSON::pretty_generate(names))
226
236
  end
227
237
  end #}}}
238
+ class Search < Riddl::Implementation #{{{
239
+ def response
240
+ where = @a[0] == :main ? '' : @r.map{ |d| Riddl::Protocols::Utils::unescape(d) }.join('/')
241
+ views = @a[1]
242
+ models = @a[2]
243
+ templates = @a[3]
244
+ default_view = @a[4]
245
+ query = @p[0].value.strip
246
+ stage = templates.keys.include?(@p[1]&.value) ? [@p[1]&.value] : [default_view]
247
+ stage << views[stage[0]] if views && views[stage[0]]
248
+
249
+ return Riddl::Parameter::Complex.new('list','application/json','[]') if query == ''
250
+
251
+ base = File.join(models,where)
252
+
253
+ # (a) names of models and dirs in and below base
254
+ names = Dir.glob('**/*.{dir,xml}', base: base).select do |f|
255
+ File.basename(f).sub(/\.(dir|xml)$/,'').downcase.include?(query.downcase)
256
+ end
257
+
258
+ # (b) contents of models in and below base, through git grep (--no-index if base is not inside a git)
259
+ _, status = Open3.capture2e('git', 'rev-parse', '--is-inside-work-tree', chdir: base)
260
+ out, _ = Open3.capture2('git', 'grep', '-I', '-i', '-F', '-o', '-z', status.success? ? '--untracked' : '--no-index', '-e', query, '--', '*.xml', chdir: base)
261
+ contents = out.split("\n").map{ |l| l.split("\0",2).first }.tally # -o yields one line per occurrence
262
+
263
+ res = (names | contents.keys).sort.map do |f|
264
+ full = File.join(base,f)
265
+ path = where == '' ? f : File.join(where,f)
266
+ attrs = JSON::load File.open(full + '.attrs') rescue {}
267
+ if f =~ /\.dir$/
268
+ { :type => :dir, :name => File.basename(f), :path => path, :creator => attrs['creator'], :date => File.mtime(full).xmlschema, :name_match => true, :content_matches => 0 }
269
+ else
270
+ fstage = attrs['design_stage'] || default_view
271
+ name_match = names.include?(f)
272
+ # each model contains its name (info) and its dir (design_dir) once, these are no real content hits
273
+ self_matches = (name_match ? 1 : 0) + (File.dirname(path) != '.' && File.dirname(path).downcase.include?(query.downcase) ? 1 : 0)
274
+ content_matches = [contents[f].to_i - self_matches, 0].max
275
+ { :type => :file, :name => File.basename(f), :path => path, :creator => attrs['creator'], :author => attrs['author'], :stage => fstage, :date => File.mtime(full).xmlschema, :name_match => name_match, :content_matches => content_matches } if stage.include?(fstage) && (name_match || content_matches > 0)
276
+ end
277
+ end.compact
278
+
279
+ Riddl::Parameter::Complex.new('list','application/json',JSON::pretty_generate(res))
280
+ end
281
+ end #}}}
228
282
  class GetStages < Riddl::Implementation #{{{
229
283
  def response
230
284
  themes = @a[0]
@@ -350,7 +404,7 @@ module CPEE
350
404
  File.write(f + '.attrs',JSON::pretty_generate(attrs))
351
405
  end
352
406
 
353
- CPEE::ModelManagement::op author, 'mv', models, File.basename(fnname), name + '.dir'
407
+ CPEE::ModelManagement::op author, 'mv', models, File.join('.', where, File.basename(fnname)), File.join('.', name + '.dir')
354
408
  CPEE::ModelManagement::notify conns, 'rename', models, fnname, default_view, fname
355
409
  nil
356
410
  end
@@ -407,11 +461,8 @@ module CPEE
407
461
  name = @r[-1].sub(/\.xml$/,'')
408
462
  source = File.join(models,where,name + '.xml')
409
463
  where = @p[0].value
410
- if @p.length > 1
411
- fname = File.join(models,where,@p[1].value + '.xml')
412
- else
413
- fname = File.join(models,where,name + '.xml')
414
- end
464
+ name = @p[1].value if @p.length > 1
465
+ fname = File.join(models,where,name + '.xml')
415
466
  end
416
467
 
417
468
  attrs = JSON::load File.open(source + '.attrs') rescue {}
@@ -456,7 +507,7 @@ module CPEE
456
507
  end
457
508
  File.write(fname + '.attrs',JSON::pretty_generate(attrs))
458
509
 
459
- CPEE::ModelManagement::op creator, 'add', models, File.join('.', where, name + '.xml')
510
+ CPEE::ModelManagement::op creator, 'add', models, File.join('.', where, File.basename(fname))
460
511
  CPEE::ModelManagement::notify conns, 'create', models, fname, default_view
461
512
  nil
462
513
  end
@@ -939,6 +990,7 @@ module CPEE
939
990
  end
940
991
 
941
992
  startup do
993
+ CPEE::ModelManagement::git_init(opts[:models])
942
994
  CPEE::ModelManagement::service_handler(opts,'restart','started')
943
995
  end
944
996
  cleanup do
@@ -949,6 +1001,7 @@ module CPEE
949
1001
  run GetList, :main, opts[:views], opts[:models], opts[:templates], opts[:default_view] if get 'stage'
950
1002
  run GetListFull, opts[:views], opts[:models], opts[:templates], opts[:default_view] if get 'full'
951
1003
  run GetStages, opts[:themes], opts[:default_view] if get 'stages'
1004
+ run Search, :main, opts[:views], opts[:models], opts[:templates], opts[:default_view] if get 'search'
952
1005
  run Create, :main, opts[:views], opts[:management_receivers], opts[:templates], opts[:models], opts[:default_view] if post 'item'
953
1006
  run CreateDir, :main, opts[:management_receivers], opts[:models], opts[:default_view] if post 'dir'
954
1007
  on resource 'management' do
@@ -956,6 +1009,7 @@ module CPEE
956
1009
  end
957
1010
  on resource '[a-zA-Z0-9öäüÖÄÜ _-]+\.dir' do
958
1011
  run GetList, :sub, opts[:views], opts[:models], opts[:templates], opts[:default_view] if get 'stage'
1012
+ run Search, :sub, opts[:views], opts[:models], opts[:templates], opts[:default_view] if get 'search'
959
1013
  run Create, :sub, opts[:views], opts[:management_receivers], opts[:templates], opts[:models], opts[:default_view] if post 'item'
960
1014
  run DeleteDir, opts[:management_receivers], opts[:models], opts[:default_view] if delete
961
1015
  run RenameDir, opts[:management_receivers], opts[:models], opts[:default_view] if put 'name'
@@ -67,6 +67,12 @@
67
67
  <parameter name="stage" type="string"/>
68
68
  </optional>
69
69
  </message>
70
+ <message name="search">
71
+ <parameter name="search" type="string"/>
72
+ <optional>
73
+ <parameter name="stage" type="string"/>
74
+ </optional>
75
+ </message>
70
76
  <message name="list">
71
77
  <parameter name="list" mimetype="application/json"/>
72
78
  </message>
@@ -79,6 +85,7 @@
79
85
  <get in="stage" out="list"/>
80
86
  <get in="full" out="list"/>
81
87
  <get in="stages" out="list"/>
88
+ <get in="search" out="list"/>
82
89
  <resource relative="management">
83
90
  <sse/>
84
91
  </resource>
@@ -86,6 +93,7 @@
86
93
  <post in="item"/>
87
94
  <post in="dir"/>
88
95
  <get in="stage" out="list"/>
96
+ <get in="search" out="list"/>
89
97
  <delete/>
90
98
  <put in="name"/> <!-- rename -->
91
99
  <resource relative="[a-zA-Z0-9&#xF6;&#xE4;&#xFC;&#xD6;&#xC4;&#xDC; _-]+\.xml">
data/ui/index.html CHANGED
@@ -25,15 +25,14 @@
25
25
 
26
26
  <!-- libs, do not modify. When local than load local libs. -->
27
27
  <script type="text/javascript" src="/js_libs/jquery.min.js"></script>
28
- <script type="text/javascript" src="/js_libs/jquery.browser.js"></script>
29
- <script type="text/javascript" src="/js_libs/printf.js"></script>
28
+ <script type="text/javascript" src="/js_libs/uidash_util.js"></script>
30
29
  <script type="text/javascript" src="/js_libs/strftime.min.js"></script>
31
30
  <script type="text/javascript" src="/js_libs/plotly.min.js"></script>
32
31
 
33
32
  <script type="text/javascript" src="/js_libs/uidash.js"></script>
34
- <script type="text/javascript" src="/js_libs/custommenu.js"></script>
33
+ <script type="text/javascript" src="/js_libs/uidash_custommenu.js"></script>
35
34
 
36
- <link rel="stylesheet" href="/js_libs/custommenu.css" type="text/css"/>
35
+ <link rel="stylesheet" href="/js_libs/uidash_custommenu.css" type="text/css"/>
37
36
  <link rel="stylesheet" href="/js_libs/uidash.css" type="text/css"/>
38
37
 
39
38
  <link rel="stylesheet" href="/global_ui/ui.css" type="text/css"/>
@@ -49,6 +48,7 @@
49
48
  <ui-tabbar>
50
49
  <ui-before ></ui-before>
51
50
  <ui-tab class="" data-tab="models" >Models</ui-tab>
51
+ <ui-tab class="inactive" data-tab="search" >Search</ui-tab>
52
52
  <ui-tab class="inactive" data-tab="newmodel" >New Model</ui-tab>
53
53
  <ui-tab class="inactive" data-tab="newdir" >New Dir</ui-tab>
54
54
  <ui-space ></ui-space>
@@ -113,7 +113,7 @@
113
113
  getting confused and shooting yourself in the foot in your little
114
114
  modelling world we allow only unique names. Better safe than sorry.
115
115
  </div>
116
- <div class="breadcrumb"><span class="crumb" onclick=""><i class="uidash-icon uidash-icon-home"></i> Home</span></div>
116
+ <div class="breadcrumb"><span class="crumb" onclick=""><i class="uidash-icon uidash-text uidash-icon-home"></i> Home</span></div>
117
117
  <form id="newmod">
118
118
  <p>
119
119
  <input type="text" name="new" required pattern="^[a-zA-Z0-9öäüÖÄÜ _\-]+" placeholder="Filename (no extension necessary). Only use characters, spaces, underlines and dashes."/>
@@ -128,7 +128,7 @@
128
128
  Create an empty directory. Beware, if a directory of the same name
129
129
  already exists it can not be created.
130
130
  </div>
131
- <div class="breadcrumb"><span class="crumb" onclick=""><i class="uidash-icon uidash-icon-home"></i> Home</span></div>
131
+ <div class="breadcrumb"><span class="crumb" onclick=""><i class="uidash-icon uidash-text uidash-icon-home"></i> Home</span></div>
132
132
  <form id="newdir">
133
133
  <p>
134
134
  <input type="text" name="newdir" required pattern="^[a-zA-Z0-9öäüÖÄÜ _\-]+" placeholder="Directory name. Only use characters, spaces, underlines and dashes."/>
@@ -138,6 +138,43 @@
138
138
  </p>
139
139
  </form>
140
140
  </ui-area>
141
+ <ui-area data-belongs-to-tab="search" class="inactive">
142
+ <div class="text">
143
+ Finds models and directories whose name contains what you are
144
+ looking for, as well as models that contain it somewhere inside
145
+ (case insensitive). Your search has to consist of more than 3
146
+ characters.
147
+ </div>
148
+ <div class="breadcrumb"><span class="crumb" onclick=""><i class="uidash-icon uidash-text uidash-icon-home"></i> Home</span></div>
149
+ <form id="search">
150
+ <p>
151
+ <input type="text" name="search" required minlength="4" placeholder="Search for model names and terms inside models (more than 3 chars)."/>
152
+ </p>
153
+ <p>
154
+ <button>Search</button>
155
+ </p>
156
+ </form>
157
+ <table id="searchresults" class='ui-table'>
158
+ <thead>
159
+ <th>Name</th>
160
+ <th>Directory</th>
161
+ <th>Found In</th>
162
+ <th>Changed By</th>
163
+ <th>Changed At</th>
164
+ </thead>
165
+ <template id="searchresult">
166
+ <tr>
167
+ <td data-class='name'><a href=''></a></td>
168
+ <td data-class='dir'><a href=''></a></td>
169
+ <td data-class='found'></td>
170
+ <td data-class='author'></td>
171
+ <td data-class='date'></td>
172
+ </tr>
173
+ </template>
174
+ <tbody>
175
+ </tbody>
176
+ </table>
177
+ </ui-area>
141
178
  <ui-area data-belongs-to-tab="instances" class="inactive">
142
179
  <p>
143
180
  Show ready, running and stopped instances.
data/ui/instances.html CHANGED
@@ -25,8 +25,7 @@
25
25
 
26
26
  <!-- libs, do not modify. When local than load local libs. -->
27
27
  <script type="text/javascript" src="/js_libs/jquery.min.js"></script>
28
- <script type="text/javascript" src="/js_libs/jquery.browser.js"></script>
29
- <script type="text/javascript" src="/js_libs/printf.js"></script>
28
+ <script type="text/javascript" src="/js_libs/uidash_util.js"></script>
30
29
  <script type="text/javascript" src="/js_libs/strftime.min.js"></script>
31
30
 
32
31
  <script type="text/javascript" src="/js_libs/uidash.js"></script>
@@ -25,8 +25,7 @@
25
25
 
26
26
  <!-- libs, do not modify. When local than load local libs. -->
27
27
  <script type="text/javascript" src="/js_libs/jquery.min.js"></script>
28
- <script type="text/javascript" src="/js_libs/jquery.browser.js"></script>
29
- <script type="text/javascript" src="/js_libs/printf.js"></script>
28
+ <script type="text/javascript" src="/js_libs/uidash_util.js"></script>
30
29
  <script type="text/javascript" src="/js_libs/strftime.min.js"></script>
31
30
 
32
31
  <script type="text/javascript" src="/js_libs/uidash.js"></script>
data/ui/js/moma.js CHANGED
@@ -200,6 +200,47 @@ function paint(pdir,gstage,statesave=true) {
200
200
  });
201
201
  }
202
202
 
203
+ function show_dir(dir) {
204
+ paint(dir,gstage);
205
+ uidash_activate_tab($('ui-tab').first());
206
+ }
207
+
208
+ function search(term) {
209
+ $.ajax({
210
+ type: "GET",
211
+ url: "server/" + gdir,
212
+ data: { search: term, stage: gstage },
213
+ success: function(res) {
214
+ $('#searchresults tbody').empty();
215
+ const rank = (data) => data.type == 'dir' ? 0 : (data['name_match'] ? 1 : 2);
216
+ res.sort((a,b) => rank(a) - rank(b));
217
+ let tempcont = $();
218
+ $(res).each(function(k,data) {
219
+ let pdir = data['path'].replace(/[^\/]*$/,'');
220
+ var clone = document.importNode(document.querySelector('#searchresult').content,true);
221
+ if (data.type == 'dir') {
222
+ $('[data-class=name] a',clone).text(data['name'].replace(/\.dir$/,'') + '/');
223
+ $('[data-class=name] a',clone).attr('href','javascript:show_dir("' + data['path'] + '")');
224
+ } else {
225
+ $('[data-class=name] a',clone).text(data['name']);
226
+ $('[data-class=name] a',clone).attr('href','server/' + data['path'] + '/open?stage=' + gstage);
227
+ $('[data-class=name] a',clone).attr('target','_blank');
228
+ }
229
+ $('[data-class=dir] a',clone).text('/' + pdir.replace(/\.dir/g,''));
230
+ $('[data-class=dir] a',clone).attr('href','javascript:show_dir("' + pdir + '")');
231
+ let found = [];
232
+ if (data['name_match']) { found.push(data.type == 'dir' ? 'directory' : 'name'); }
233
+ if (data['content_matches'] > 0) { found.push('content (' + data['content_matches'] + (data['content_matches'] == 1 ? ' time)' : ' times)')); }
234
+ $('[data-class=found]',clone).text(found.join(', '));
235
+ $('[data-class=author]',clone).text(data['author'] || data['creator']);
236
+ $('[data-class=date]',clone).text(new Date(data['date']).strftime('%Y-%m-%d, %H:%M:%S'));
237
+ tempcont.push(clone);
238
+ });
239
+ $('#searchresults tbody').append(tempcont);
240
+ }
241
+ });
242
+ }
243
+
203
244
  function change_it(gdir,gstage) {
204
245
  window.location.href = window.location.pathname + '?stage=' + gstage + '&dir=' + gdir;
205
246
  }
@@ -414,4 +455,9 @@ $(document).ready(function() {
414
455
  });
415
456
  return false;
416
457
  });
458
+
459
+ $('#search').on('submit',(e) => {
460
+ search($("#search input[name=search]").val());
461
+ return false;
462
+ });
417
463
  });
data/ui/js/stats.js CHANGED
@@ -98,8 +98,8 @@ function instance_upd(uuid,name,state,author,cpu,mem,time,parent) {
98
98
  instance_res(uuid,cpu,mem)
99
99
  }
100
100
  function instance_res(uuid,cpu,mem) {
101
- $('[data-id=' + uuid + '] > .cpu').text($.sprintf('%05.2f',cpu))
102
- $('[data-id=' + uuid + '] > .mem').text($.sprintf('%05.2f',mem))
101
+ $('[data-id=' + uuid + '] > .cpu').text(cpu.sprintf('%05.2f'))
102
+ $('[data-id=' + uuid + '] > .mem').text(mem.sprintf('%05.2f'))
103
103
  }
104
104
  function instance_add(iname,uuid,url,name,state,author,cpu,mem,time,parent) {
105
105
  let inode = document.importNode($("#stats_instance")[0].content,true);
@@ -119,8 +119,8 @@ function instance_add(iname,uuid,url,name,state,author,cpu,mem,time,parent) {
119
119
  if (author != "") {
120
120
  $('.author',inode).text(author)
121
121
  }
122
- $('.cpu',inode).text($.sprintf('%05.2f',cpu))
123
- $('.mem',inode).text($.sprintf('%05.2f',mem))
122
+ $('.cpu',inode).text(cpu.sprintf('%05.2f'))
123
+ $('.mem',inode).text(mem.sprintf('%05.2f'))
124
124
  $('.time',inode).text((new Date(time * 1000)).strftime("%H:%M:%S (%b-%d)"))
125
125
  if (parent == "") {
126
126
  $('#instances_' + iname).append(inode)
data/ui/resources.html CHANGED
@@ -25,7 +25,7 @@
25
25
 
26
26
  <!-- libs, do not modify. When local than load local libs. -->
27
27
  <script type="text/javascript" src="/js_libs/jquery.min.js"></script>
28
- <script type="text/javascript" src="/js_libs/jquery.browser.js"></script>
28
+ <script type="text/javascript" src="/js_libs/uidash_util.js"></script>
29
29
  <script type="text/javascript" src="/js_libs/plotly.min.js"></script>
30
30
 
31
31
  <script type="text/javascript" src="/js_libs/uidash.js"></script>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpee-model-management
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.10
4
+ version: 1.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen eTM Mangler