sortablelabel_js 0.1.0

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: 4d5eb919c60f682748ab4554210be055e3202697
4
+ data.tar.gz: a58c9408a6ede558daa1df9d7075a3db1a725a4d
5
+ SHA512:
6
+ metadata.gz: 1f4ee538764347f6ef0ff9f3e56d3ea89c12aa5290113ff2a438eab4858422ce897765b111747b0a47d00808e53266654c66d62f434d9caa760b041bce15558e
7
+ data.tar.gz: 49d7fa02fdfc09a6a1e1607d629968069c60c263eda198111853c251ed5748fc5b82dec07070c1dab023f13f03ac40382bee22c4d86da611f2b1c491f9b17161
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /bower_components
2
+ /node_modules
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,35 @@
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/[USERNAME]/sortablelabel-js.
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": "",
4
+ "main": "index.js",
5
+ "authors": [
6
+ "Joe <ashzhouyue@gmail.com>"
7
+ ],
8
+ "license": "ISC",
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,8 @@
1
+ require "sortablelabel/js/version"
2
+
3
+ module Sortablelabel
4
+ module Js
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Sortablelabel
2
+ module Js
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
data/my.conf.js ADDED
@@ -0,0 +1,91 @@
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/*.coffee': ['coffee']
42
+ },
43
+
44
+ coffeePreprocessor: {
45
+ // options passed to the coffee compiler
46
+ options: {
47
+ bare: true,
48
+ sourceMap: false
49
+ },
50
+ // transforming the filenames
51
+ transformPath: function(path) {
52
+ return path.replace(/\.coffee$/, '.js')
53
+ }
54
+ },
55
+ // test results reporter to use
56
+ // possible values: 'dots', 'progress'
57
+ // available reporters: https://npmjs.org/browse/keyword/karma-reporter
58
+ reporters: ['progress'],
59
+
60
+
61
+ // web server port
62
+ port: 9876,
63
+
64
+
65
+ // enable / disable colors in the output (reporters and logs)
66
+ colors: true,
67
+
68
+
69
+ // level of logging
70
+ // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
71
+ logLevel: config.LOG_INFO,
72
+
73
+
74
+ // enable / disable watching file and executing tests whenever any file changes
75
+ autoWatch: true,
76
+
77
+
78
+ // start these browsers
79
+ // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
80
+ browsers: ['Chrome'],
81
+
82
+
83
+ // Continuous Integration mode
84
+ // if true, Karma captures browsers, runs the tests and exits
85
+ singleRun: false,
86
+
87
+ // Concurrency level
88
+ // how many browser should be started simultaneous
89
+ concurrency: Infinity
90
+ })
91
+ }
data/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "sortlabel",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "./node_modules/karma/bin/karma start my.conf.js"
8
+ },
9
+ "author": "",
10
+ "license": "ISC",
11
+ "devDependencies": {
12
+ "jasmine-core": "^2.7.0",
13
+ "karma": "^1.7.0",
14
+ "karma-chrome-launcher": "^2.2.0",
15
+ "karma-coffee-preprocessor": "^1.0.1",
16
+ "karma-jasmine": "^1.1.0",
17
+ "karma-jasmine-jquery": "^0.1.1"
18
+ }
19
+ }
@@ -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,118 @@
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'])
53
+
54
+ calStepLable: ->
55
+ this.calLabel(this.options['removeField']+'[value=false]')
56
+ if this.options['weekGroupLabelTarget']
57
+ this.calWeekGroupLabel(this.options['weekGroupLabelTarget'])
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) ->
88
+ _this = this
89
+ week_group_label_list = []
90
+ $(@target.selector).each(->
91
+ $(this).find(target).each(->
92
+ _index = _this.isIncludeWeekGroup($(this).text(), week_group_label_list)
93
+ if _index is -1
94
+ week_group_label_list.push(
95
+ name: $(this).text(),
96
+ count: 1
97
+ )
98
+ $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>"+$(this).text()+" 1")
99
+ else if _index > -1
100
+ week_group_label_list[_index].count += 1
101
+ $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>"+$(this).text()+" "+week_group_label_list[_index].count)
102
+ )
103
+ )
104
+
105
+ isIncludeWeekGroup: (item, arr)->
106
+ if item == " "
107
+ return -2
108
+ for _item, index in arr
109
+ return index if _item.name is item
110
+ return -1
111
+
112
+ dayOfWeek: (dayIndex) ->
113
+ ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"][dayIndex]
114
+
115
+ (($) ->
116
+ $.fn.sortableLabel = (options) ->
117
+ new SortableLabel(this, options)
118
+ )(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.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joe
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-01 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: []