thecore_dataentry_commons 1.2.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d8009c4b390ff3364b0acc7dee626eacb3425f23
4
+ data.tar.gz: 11327a748ab56f7b01a279e5c00282ff28525dec
5
+ SHA512:
6
+ metadata.gz: b1f8f0757cdc25170c80f651298e42e15d576fb5b8d5af9db1cbe28277cdcf83a64ca9cd1888f0c5875e404423273ab915f540560696f2b442c3b98c56917cf3
7
+ data.tar.gz: f99e88bfaa223f8557c12e1e6644e772ea67e66c69c8910bf89e935594e6432694800a38e08b6ac8c5dde3eb8cbf918453b62614b5643b961c037598e8df0d41
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Gabriele Tassoni
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # ThecoreDatawedgeWebsocketHelpers
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'thecore_dataentry_commons'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install thecore_datawedge_websocket_helpers
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,115 @@
1
+ <%= breadcrumb %>
2
+
3
+ <%= render "barcode_scan_mode_detection"%>
4
+ <%= render "dataentry_commons_input_group" %>
5
+
6
+ <div class="container" style="margin-top: 1em;">
7
+ <div class="row">
8
+ <div id="data-info" class="alert alert-warning col-lg-12"></div>
9
+ </div>
10
+ <div class="row">
11
+ <div id="data-content" class="alert alert-warning col-lg-12"></div>
12
+ </div>
13
+ <%-unless (hide_action rescue true)%>
14
+ <div class="row">
15
+ <button id="data-action" class="btn btn-danger col-lg-12" data-loading-text="<i class='fa fa-spinner fa-spin '></i> <%=t :loading %>"><%=t "barcode.action.name"%></button>
16
+ </div>
17
+ <%-end%>
18
+ </div>
19
+
20
+ <script>
21
+ var code;
22
+ var returnedData;
23
+
24
+ // These functions can be overridden in the containing file
25
+ function setAll() {
26
+ $("#data-info").show();
27
+ $("#data-content").show();
28
+ <%-unless (hide_action rescue true)%>
29
+ $("#data-action").show();
30
+ <%-end%>
31
+ }
32
+
33
+ function resetInfo() {
34
+ returnedData = code = undefined;
35
+ $("#barcode").empty();
36
+ $("#data-info").empty().hide();
37
+ $("#data-content").empty().hide();
38
+ <%-unless (hide_action rescue true)%>
39
+ $("#data-action").hide();
40
+ <%-end%>
41
+ }
42
+
43
+ function contentHtmlString(data){
44
+ return data.barcode;
45
+ }
46
+
47
+ function barcodeScannedSuccess(data, status) {
48
+ returnedData = data;
49
+ // Cleaning up
50
+ $("#data-content").empty().hide();
51
+ // Setting info already formatted from the controller
52
+ $("#data-info").html(data.info);
53
+ // Setting returned content
54
+ var appended = contentHtmlString(data).appendTo("#data-content");
55
+ // $("#data-content").switchClass("alert-warning", "alert-success", 800).switchClass("alert-success", "alert-warning",800);
56
+ setAll();
57
+ resetCurrentBtn();
58
+ return appended;
59
+ }
60
+
61
+ function barcodeScannedThen(appended){}
62
+
63
+ function barcodeScannedFailure(errorObj) {
64
+ // Resetting all to the starting condition
65
+ resetCurrentBtn();
66
+ resetInfo();
67
+ // Showing modal error
68
+ openModal("<%=t :error %>", errorObj.responseJSON.error);
69
+ }
70
+
71
+ <%-unless (hide_action rescue true)%>
72
+ function dataActionSuccess(data, status) {
73
+ openModal("<%=t :success %>", data.message);
74
+ setAll();
75
+ resetCurrentBtn();
76
+ return data;
77
+ }
78
+
79
+ function dataActionThen(data){}
80
+
81
+ function dataActionFailure(errorObj) {
82
+ barcodeScannedFailure(errorObj);
83
+ }
84
+ <%-end%>
85
+ // END of overridable functions
86
+
87
+ // Operation on barcode scan
88
+ $('#send').on('click', function () {
89
+ code = $('#barcode');
90
+ code.prop('disabled', true);
91
+ $(this).button('loading');
92
+ $.get('<%=rails_admin.send("#{action_name}_path")%>', {
93
+ barcode: code.val()
94
+ }).then(barcodeScannedSuccess).done(barcodeScannedThen).fail(barcodeScannedFailure);
95
+ });
96
+
97
+ <%-unless (hide_action rescue true)%>
98
+ // Operation on button click
99
+ $("#data-action").click(function () {
100
+ code = $('#barcode');
101
+ code.prop('disabled', true);
102
+ $(this).button('loading');
103
+ $.get('<%=rails_admin.send("#{action_name}_path")%>', {
104
+ barcode: code.val(),
105
+ action: "data-action",
106
+ data: returnedData
107
+ }).then(dataActionSuccess).done(dataActionThen).fail(dataActionFailure);
108
+ });
109
+ <%-end%>
110
+
111
+ // Starting with a clean interface
112
+ resetInfo();
113
+ </script>
114
+
115
+ <%= render "dataentry_commons_input_group_logic" %>
@@ -0,0 +1,11 @@
1
+ <!-- Automatically manage kp or ws mode, based on the auto setting and detection of mobile or not browser -->
2
+ <%-@type = "kp"%>
3
+ <%-if Settings.datawedge_scan_mode == "auto"%>
4
+ <%-Rails.logger.debug "META #{browser.meta.inspect}\n - includes mobile? #{browser.meta.include?("mobile")}\n - includes android? #{browser.meta.include?("android")}"%>
5
+ <%-if browser.meta.include?("mobile") && browser.meta.include?("android")%>
6
+ <%-@type = "ws"%>
7
+ <%-end%>
8
+ <%-else%>
9
+ <%-@type = Settings.datawedge_scan_mode%>
10
+ <%-end%>
11
+ <%-Rails.logger.debug "Computed type: #{@type}"%>
@@ -0,0 +1,45 @@
1
+ <%-if @type == "ws" %>
2
+ <style type="text/css">
3
+ .input-group-addon.primary {
4
+ color: rgb(255, 255, 255);
5
+ background-color: rgb(50, 118, 177);
6
+ border-color: rgb(40, 94, 142);
7
+ }
8
+ .input-group-addon.success {
9
+ color: rgb(255, 255, 255);
10
+ background-color: rgb(92, 184, 92);
11
+ border-color: rgb(76, 174, 76);
12
+ }
13
+ .input-group-addon.info {
14
+ color: rgb(255, 255, 255);
15
+ background-color: rgb(57, 179, 215);
16
+ border-color: rgb(38, 154, 188);
17
+ }
18
+ .input-group-addon.warning {
19
+ color: rgb(255, 255, 255);
20
+ background-color: rgb(240, 173, 78);
21
+ border-color: rgb(238, 162, 54);
22
+ }
23
+ .input-group-addon.danger {
24
+ color: rgb(255, 255, 255);
25
+ background-color: rgb(217, 83, 79);
26
+ border-color: rgb(212, 63, 58);
27
+ }
28
+ </style>
29
+ <%-end%>
30
+
31
+ <div class="row" id="barcode-container">
32
+ <div class="col-lg-12">
33
+ <div class="input-group input-group-lg">
34
+ <%-if @type == "ws" %>
35
+ <span id="connection" class="input-group-addon danger">
36
+ <i class='fa fa-plug'></i>
37
+ </span>
38
+ <%-end%>
39
+ <input type="text" name="barcode" class="form-control input-lg" id="barcode" placeholder="<%= I18n.t :manual_barcode %>"/>
40
+ <span class="input-group-btn">
41
+ <button id="send" type="button" class="btn btn-default btn-lg" data-loading-text="<i class='fa fa-spinner fa-spin '></i> <%=t :loading %>"><%= I18n.t :send %></button>
42
+ </span>
43
+ </div>
44
+ </div>
45
+ </div>
@@ -0,0 +1 @@
1
+ <%=render(@type) rescue render("kp")%>
@@ -0,0 +1,54 @@
1
+ <script>
2
+ function keypressAndReturn(event) {
3
+ // Capture all the keypresses and if they are a return,
4
+ // then "click" the send button
5
+ event.stopPropagation();
6
+ var keycode = (event.keyCode ? event.keyCode : event.which);
7
+ //console.log(keycode);
8
+ if (keycode == '13') {
9
+ $("#send").click();
10
+ return true;
11
+ }
12
+ return false;
13
+ }
14
+ var kpMode = "<%= Settings.datawedge_kp_mode %>";
15
+ // var clickedBtn; var code; Gestisco il keypress sull'input
16
+ $("input[name=barcode]").on(kpMode, keypressAndReturn);
17
+
18
+ function resetCurrentBtn() {
19
+ $("#send").button('reset');
20
+ $("#barcode").prop('disabled', false);
21
+ $("#barcode").val('');
22
+ // sendMessageToServer(msg_input_plugin_enable); clickedBtn = code = null;
23
+ }
24
+ // var clickedBtn; var code; Gestisco il keypress sull'input
25
+ function manageScannedKeystrokes(event) {
26
+ if(!keypressAndReturn(event)) {
27
+ $("#send").focus();
28
+ // Scrivilo nell'input field (accumulando)
29
+ $("input[name=barcode]").val(function (index, val) {
30
+ // Scrivo
31
+ return val + event.key;
32
+ });
33
+ }
34
+ }
35
+ function enableKSCapture(){
36
+ $(document).on(kpMode, manageScannedKeystrokes);
37
+ }
38
+ function disableKSCapture(){
39
+ $(document).off(kpMode, manageScannedKeystrokes);
40
+ }
41
+
42
+ // Init
43
+ enableKSCapture();
44
+ // Se $("#barcode") si becca il focus, elimino il keypress
45
+ $("#barcode").focusin(function () {
46
+ // Blocco il keypress del document
47
+ disableKSCapture();
48
+ });
49
+ $("#barcode").focusout(function () {
50
+ // Blocco il keypress del document
51
+ enableKSCapture();
52
+ });
53
+ $("#send").focus();
54
+ </script>
@@ -0,0 +1,80 @@
1
+ <input id="label-type" name="label-type" type="hidden"/>
2
+ <script>
3
+ // Proof of concept to control DataWedge via Web Sockets
4
+ var msg_input_plugin_enable = {
5
+ "action": "com.symbol.datawedge.api.ACTION_SCANNERINPUTPLUGIN",
6
+ "extra_key": "com.symbol.datawedge.api.EXTRA_PARAMETER",
7
+ "extra_value": "ENABLE_PLUGIN"
8
+ };
9
+ var msg_input_plugin_disable = {
10
+ "action": "com.symbol.datawedge.api.ACTION_SCANNERINPUTPLUGIN",
11
+ "extra_key": "com.symbol.datawedge.api.EXTRA_PARAMETER",
12
+ "extra_value": "DISABLE_PLUGIN"
13
+ };
14
+
15
+ // WEBSOCKET ----------------------------------------------------------------------------------
16
+ var socketClosed = true;
17
+ var address = "127.0.0.1";
18
+ var port = "12345";
19
+
20
+ function socketOnError() {
21
+ console.log("Error");
22
+ if (!socketClosed) {
23
+ socketClosed = true;
24
+ ws.close();
25
+ }
26
+ }
27
+
28
+ var barcodeScanRegExp = /Barcode \((.*)\) \[(.*)\]/;
29
+
30
+ function init() {
31
+ ws = new WebSocket("ws://" + address + ":" + port + "/");
32
+ ws.onmessage = function (event) {
33
+ // event.data ha forma: Barcode (8273878337383) [LABEL-TYPE-EAN13]
34
+ // il barcode è event.extras["com.symbol.datawedge.data_string"]: String contains the output data as a String. In the case of concatenated barcodes, the decode data is concatenated and sent out as a single string. In the example above: 8273878337383
35
+ // il label_type è event.extras["com.symbol.datawedge.label_type"]: String contains the barcode label type. In the example above: LABEL-TYPE-EAN13
36
+ // il decode_data è event.extras["com.symbol.datawedge.decode_data"]: Decode data is returned as a list of byte arrays. In most cases there will be one byte array per decode. For barcode symbologies that support concatenation (i.e. Codabar, Code128, MicroPDF, etc.) the decoded data is stored in multiple byte arrays (one byte array per bar code). Clients can get data in each byte array by passing an index.
37
+ var results = barcodeScanRegExp.exec(event.data);
38
+ $('input[name=barcode]').val(results[1]);
39
+ $('input[name=label-type]').val(results[2]);
40
+ $("#send").click();
41
+ };
42
+ // In production you would want this to be resiliant against the server being killed by Android, by the user navigating between pages or any other unexpected error related to connection.
43
+ ws.onclose = function () {
44
+ setSocketStatus("success", "danger");
45
+ socketClosed = true;
46
+ };
47
+ ws.onopen = function () {
48
+ setSocketStatus("danger", "success");
49
+ socketClosed = false;
50
+ };
51
+ ws.onerror = function (event) {
52
+ socketOnError();
53
+ };
54
+ }
55
+ function setSocketStatus(origin, to) {
56
+ $('#connection').removeClass(origin).addClass(to);
57
+ }
58
+ // function sendMessageToServer(json_msg) {
59
+ // if (socketClosed) {
60
+ // init();
61
+ // } else {
62
+ // ws.send(JSON.stringify(json_msg), function (error) {
63
+ // socketOnError();
64
+ // });
65
+ // }
66
+ // }
67
+
68
+ function tryInit() {
69
+ // Solo se la socket è chiusa e siamo in ambiente android
70
+ if (socketClosed) {
71
+ init();
72
+ }
73
+ }
74
+ // Creating the websocket
75
+ var ua = navigator.userAgent.toLowerCase();
76
+ var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
77
+ if (isAndroid) {
78
+ setInterval(tryInit, 1500);
79
+ }
80
+ </script>
@@ -0,0 +1,14 @@
1
+ en:
2
+ ask_yes: Yes
3
+ ask_no: Cancel
4
+ error: Error
5
+ success: Successo
6
+ question: Question
7
+ manual_barcode: Manual input
8
+ barcode_cannot_be_empty: Barcode cannot be empty
9
+ send: Send
10
+ loading: Loading
11
+ barcode:
12
+ action:
13
+ name:
14
+ Send
@@ -0,0 +1,14 @@
1
+ it:
2
+ ask_yes: Si
3
+ ask_no: Annulla
4
+ error: Errore
5
+ success: Successo
6
+ question: Domanda
7
+ manual_barcode: Inserimento Manuale
8
+ barcode_cannot_be_empty: Il codice a barre letto non può essere vuoto
9
+ send: Invia
10
+ loading: Caricamento
11
+ barcode:
12
+ action:
13
+ name:
14
+ Invia
@@ -0,0 +1,7 @@
1
+ class AddKeymodeToSettings < ActiveRecord::Migration[5.1]
2
+ def change
3
+ # keyup
4
+ # keypress
5
+ Settings.datawedge_kp_mode = "keypress"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class ReplaceWithAutoToSettings < ActiveRecord::Migration[5.1]
2
+ def change
3
+ # ws: WebSocket
4
+ # kp: KeyPress
5
+ Settings.datawedge_scan_mode = "auto" # or "kp"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require "thecore_settings"
2
+ require "thecore_dataentry_commons/engine"
3
+ require "browser"
4
+
5
+ module ThecoreDataentryCommons
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,13 @@
1
+ module ThecoreDataentryCommons
2
+ class Engine < ::Rails::Engine
3
+
4
+ initializer 'thecore_dataentry_commons.add_to_migrations' do |app|
5
+ unless app.root.to_s == root.to_s
6
+ # APPEND TO MAIN APP MIGRATIONS FROM THIS GEM
7
+ config.paths['db/migrate'].expanded.each do |expanded_path|
8
+ app.config.paths['db/migrate'] << expanded_path
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module ThecoreDataentryCommons
2
+ VERSION = '1.2.14'
3
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thecore_dataentry_commons
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.14
5
+ platform: ruby
6
+ authors:
7
+ - Gabriele Tassoni
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thecore_settings
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: browser
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.5'
41
+ description: This plugin adds some partials to deal with DataWedge WebSocket.
42
+ email:
43
+ - gabriele.tassoni@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - README.md
50
+ - app/views/higher_level/_barcode_simple_scan.html.erb
51
+ - app/views/rails_admin/main/_barcode_scan_mode_detection.html.erb
52
+ - app/views/rails_admin/main/_dataentry_commons_input_group.html.erb
53
+ - app/views/rails_admin/main/_dataentry_commons_input_group_logic.html.erb
54
+ - app/views/rails_admin/main/_kp.html.erb
55
+ - app/views/rails_admin/main/_ws.html.erb
56
+ - config/locales/en.thecore_datawedge_websocket_helpers.yml
57
+ - config/locales/it.thecore_datawedge_websocket_helpers.yml
58
+ - db/migrate/20170913192906_add_keymode_to_settings.rb
59
+ - db/migrate/20171005162605_replace_with_auto_to_settings.rb
60
+ - lib/thecore_dataentry_commons.rb
61
+ - lib/thecore_dataentry_commons/engine.rb
62
+ - lib/thecore_dataentry_commons/version.rb
63
+ homepage: https://www.taris.it
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.6.14
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Some javascripts and partials to handle DW WS.
87
+ test_files: []