sortablelabel-js 0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 71385c5813d4188ea83464d76fdd1f6950a90539
4
+ data.tar.gz: ea864efa48fd500c6115d8e841c63a10f0672371
5
+ SHA512:
6
+ metadata.gz: d898130a6a34b2cd01bf72ddb5edd783a0e40ac8564e89de56a95f7c2ebe212aa5bf57ce2f44ec7dae56f43742d269192fe3c91c94f3bc97999694be8bc796e2
7
+ data.tar.gz: 804c7d4a29d044a44bdf0463721ecbf2b620af54969f8052a4f5b6c218601e87302a0b3dff31fbdfb6e80e04bd50f9027f5d8a1e5e09fff2251e4247c2520840
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ /pkg
2
+ /bower_components
3
+ /node_modules
4
+ /coverage
5
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sortablelabel-js.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Sortablelabel::Js
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sortablelabel/js`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sortablelabel-js'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sortablelabel-js
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ZYMoridae/sortablelabel-js.
36
+
37
+
38
+
39
+ ## How to run test
40
+
41
+ #### Step 1
42
+ Install dependencies lib
43
+ ```
44
+ npm run-script plugin
45
+ ```
46
+
47
+ #### Step 2
48
+ ```
49
+ npm test
50
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sortablelabel/js"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bower.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "sortlabel",
3
+ "description": "Sortable label js dependencies",
4
+ "main": "index.js",
5
+ "authors": [
6
+ "Joe <ashzhouyue@gmail.com>"
7
+ ],
8
+ "license": "MIT",
9
+ "homepage": "",
10
+ "ignore": [
11
+ "**/.*",
12
+ "node_modules",
13
+ "bower_components",
14
+ "test",
15
+ "tests"
16
+ ],
17
+ "dependencies": {
18
+ "jquery": "^3.2.1",
19
+ "jasmine-jquery": "^2.1.1",
20
+ "jquery-sortable": "^0.9.13",
21
+ "jquery-ui": "^1.12.1"
22
+ }
23
+ }
@@ -0,0 +1,5 @@
1
+ module Sortablelabel
2
+ module Js
3
+ VERSION = "0.2"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require "sortablelabel/js/version"
2
+
3
+ module Sortablelabel
4
+ module Js
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
data/my.conf.js ADDED
@@ -0,0 +1,97 @@
1
+ // Karma configuration
2
+ // Generated on Tue Aug 01 2017 10:08:19 GMT+0930 (ACST)
3
+
4
+ module.exports = function(config) {
5
+ config.set({
6
+
7
+ // base path that will be used to resolve all patterns (eg. files, exclude)
8
+ basePath: '',
9
+
10
+
11
+ // frameworks to use
12
+ // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
13
+ frameworks: ['jasmine'],
14
+
15
+
16
+ // list of files / patterns to load in the browser
17
+ files: [
18
+ 'bower_components/jquery/dist/jquery.js',
19
+ 'bower_components/jquery-ui/jquery-ui.js',
20
+ 'bower_components/jquery-sortable/source/js/jquery-sortable.js',
21
+ 'bower_components/jasmine-jquery/lib/jasmine-jquery.js',
22
+ 'spec/javascripts/*.js',
23
+ 'vendor/assets/javascripts/*.coffee',
24
+ {
25
+ pattern: 'spec/javascripts/fixtures/*.html',
26
+ watched: true,
27
+ included: false,
28
+ served: true
29
+ },
30
+ ],
31
+
32
+
33
+ // list of files to exclude
34
+ exclude: [
35
+ ],
36
+
37
+
38
+ // preprocess matching files before serving them to the browser
39
+ // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
40
+ preprocessors: {
41
+ 'vendor/assets/javascripts/sortable_label.coffee': ['coverage'],
42
+ 'vendor/assets/javascripts/*.coffee': ['coffee']
43
+ },
44
+
45
+ coffeePreprocessor: {
46
+ // options passed to the coffee compiler
47
+ options: {
48
+ bare: true,
49
+ sourceMap: false
50
+ },
51
+ // transforming the filenames
52
+ transformPath: function(path) {
53
+ return path.replace(/\.coffee$/, '.js')
54
+ }
55
+ },
56
+ // test results reporter to use
57
+ // possible values: 'dots', 'progress'
58
+ // available reporters: https://npmjs.org/browse/keyword/karma-reporter
59
+ reporters: ['progress', 'coverage'],
60
+
61
+
62
+ // web server port
63
+ port: 9876,
64
+
65
+
66
+ // enable / disable colors in the output (reporters and logs)
67
+ colors: true,
68
+
69
+
70
+ // level of logging
71
+ // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
72
+ logLevel: config.LOG_INFO,
73
+
74
+
75
+ // enable / disable watching file and executing tests whenever any file changes
76
+ autoWatch: true,
77
+
78
+
79
+ // start these browsers
80
+ // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
81
+ browsers: ['Chrome'],
82
+
83
+
84
+ // Continuous Integration mode
85
+ // if true, Karma captures browsers, runs the tests and exits
86
+ singleRun: false,
87
+
88
+ // Concurrency level
89
+ // how many browser should be started simultaneous
90
+ concurrency: Infinity,
91
+
92
+ coverageReporter: {
93
+ type : 'html',
94
+ dir : 'coverage/'
95
+ }
96
+ })
97
+ }
data/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "sortlabel",
3
+ "version": "1.0.0",
4
+ "description": "Extension of jquery-sortable javascript library",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "./node_modules/karma/bin/karma start my.conf.js",
8
+ "dependency": "npm install | bower install"
9
+ },
10
+ "author": "",
11
+ "license": "MIT",
12
+ "devDependencies": {
13
+ "jasmine-core": "^2.7.0",
14
+ "karma": "^1.7.0",
15
+ "karma-chrome-launcher": "^2.2.0",
16
+ "karma-coffee-preprocessor": "^1.0.1",
17
+ "karma-coverage": "^1.1.1",
18
+ "karma-jasmine": "^1.1.0",
19
+ "karma-jasmine-jquery": "^0.1.1"
20
+ }
21
+ }
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "sortablelabel/js/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sortablelabel-js"
8
+ spec.version = Sortablelabel::Js::VERSION
9
+ spec.authors = ["Joe"]
10
+ spec.email = ["ashzhouyue@gmail.com"]
11
+
12
+ spec.summary = "Sortable label plugin for the project"
13
+ spec.description = "Sortable label plugin for the project"
14
+ spec.homepage = "https://github.com/johnny/jquery-sortable"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.15"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ end
@@ -0,0 +1,123 @@
1
+ class @SortableLabel
2
+
3
+ defaults =
4
+ sortableItem: '> div.fields'
5
+ labelTarget: 'label'
6
+ positionTarget: '.position-field'
7
+ nestedTarget: null
8
+ removeField: "input[id$='_destroy']"
9
+ label: 'Step '
10
+ minimun: 0
11
+
12
+ constructor: (scope, options) ->
13
+ @options = $.extend({}, defaults, options)
14
+ @target = scope
15
+ @targetId = @options['fieldName'] || @target.attr('id')
16
+ @calInitStepLable()
17
+
18
+ $(document).on("nested:fieldAdded:#{@targetId}", (event) =>
19
+ @calStepLable()
20
+ if @options['nestedTarget']
21
+ @options['nestedTarget'].call(@target)
22
+ )
23
+
24
+ $(document).on("nested:fieldRemoved:#{@targetId}", (event) =>
25
+ @calStepLable()
26
+ )
27
+
28
+ @target.on('sortableLabel:refresh', =>
29
+ @target.sortable("enable")
30
+ @calStepLable()
31
+ )
32
+
33
+ if @options['nestedTarget']
34
+ @options['nestedTarget'].call(@target)
35
+
36
+ @target.sortable(
37
+ items: @options['sortableItem']
38
+ placeholder: "ui-state-highlight"
39
+ start: (event, ui)->
40
+ $(this).find('.ui-state-highlight').css('height', $(ui.item).css('height'))
41
+ stop: =>
42
+ @calStepLable()
43
+ )
44
+
45
+ @target.on('sortableLabel:disable', =>
46
+ @target.sortable('disable')
47
+ )
48
+
49
+ calInitStepLable: ->
50
+ this.calLabel(this.options['removeField']+'[value=false]')
51
+ if this.options['weekGroupLabelTarget']
52
+ this.calWeekGroupLabel(this.options['weekGroupLabelTarget'], true)
53
+
54
+ calStepLable: ->
55
+ this.calLabel(this.options['removeField']+'[value=false]')
56
+ if this.options['weekGroupLabelTarget']
57
+ this.calWeekGroupLabel(this.options['weekGroupLabelTarget'], false)
58
+
59
+ calLabel: (target) ->
60
+ _this = this
61
+ $(@target).each(->
62
+ stepCount = 1
63
+ $(this).find(target).each( ->
64
+ if typeof(_this.options['label']) == 'string'
65
+ if _this.options['label'].trim() == 'Day'
66
+ $(this).closest('.fields').find(_this.options['labelTarget']).html(_this.dayOfWeek(stepCount - 1))
67
+ stepCount += 1
68
+ else
69
+ if _this.options['fieldName']
70
+ if $(this).closest('.fields').find('.remove_nested_fields').data('association') == _this.options['fieldName']
71
+ $(this).closest('.fields').find(_this.options['labelTarget']).html(_this.options['label'] + stepCount)
72
+ stepCount += 1
73
+ else
74
+ throw "Field name can't be empty!"
75
+ else if typeof(_this.options['label']) == 'function'
76
+ $(this).closest('.fields').find(_this.options['labelTarget']).html(_this.options['label'].call($(this).closest('.fields').find(_this.options['labelTarget']), stepCount))
77
+ stepCount += 1
78
+ $(this).closest('.fields').find(_this.options['positionTarget']).val(stepCount)
79
+ if _this.options['minimun'] >= stepCount
80
+ $(this).closest('.fields').find('.remove_nested_fields').hide();
81
+ else
82
+ $(this).closest('.fields').find('.remove_nested_fields').show();
83
+
84
+ )
85
+ )
86
+
87
+ calWeekGroupLabel: (target, is_first) ->
88
+ _this = this
89
+ week_group_label_list = []
90
+ $(@target).each(->
91
+ $(this).find(target).each(->
92
+ tempLabel = ''
93
+ if is_first
94
+ tempLabel = $(this).text()
95
+ else
96
+ tempLabel = $(this).text().substr(0, $(this).text().lastIndexOf(' '))
97
+ _index = _this.isIncludeWeekGroup(tempLabel, week_group_label_list)
98
+ if _index is -1
99
+ week_group_label_list.push(
100
+ name: tempLabel,
101
+ count: 1
102
+ )
103
+ $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>" + tempLabel + " 1")
104
+ else if _index > -1
105
+ week_group_label_list[_index].count += 1
106
+ $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>" + tempLabel + " " + week_group_label_list[_index].count)
107
+ )
108
+ )
109
+
110
+ isIncludeWeekGroup: (item, arr)->
111
+ if item == " "
112
+ return -2
113
+ for _item, index in arr
114
+ return index if _item.name is item
115
+ return -1
116
+
117
+ dayOfWeek: (dayIndex) ->
118
+ ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"][dayIndex]
119
+
120
+ (($) ->
121
+ $.fn.sortableLabel = (options) ->
122
+ new SortableLabel(this, options)
123
+ )(jQuery)
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sortablelabel-js
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.2'
5
+ platform: ruby
6
+ authors:
7
+ - Joe
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Sortable label plugin for the project
56
+ email:
57
+ - ashzhouyue@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - README.md
65
+ - Rakefile
66
+ - bin/console
67
+ - bin/setup
68
+ - bower.json
69
+ - lib/sortablelabel/js.rb
70
+ - lib/sortablelabel/js/version.rb
71
+ - my.conf.js
72
+ - package.json
73
+ - sortablelabel-js.gemspec
74
+ - vendor/assets/javascripts/sortable_label.coffee
75
+ homepage: https://github.com/johnny/jquery-sortable
76
+ licenses: []
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.4.8
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Sortable label plugin for the project
98
+ test_files: []