zwr 0.1.6 → 0.1.7

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
  SHA1:
3
- metadata.gz: 96c982be5d8c56abeb24702d370bfa484a0032d0
4
- data.tar.gz: 7b28e5b299ec174bcf5280f28d123ac681038390
3
+ metadata.gz: 3da34572c18b8f6fbe7fffdd3c0a817a8739df5d
4
+ data.tar.gz: 485c438b2432f114e484108896199769b971af35
5
5
  SHA512:
6
- metadata.gz: 5949292837a2f2650cbf5b3b9c0b63ff186c4d20fd974ee10db74680534ba4d5e39de83a69ea81b8035241d7c39fd32fe1280a52ecad295ad37f2740041008db
7
- data.tar.gz: 50d6512c81b3303e168a254cceeec17e3748b4c2eccf783f23a63351573b4f201b0861d43c8e26b21c5f3b4bf5cedd2a3ce30a8fc36a6f4cb5639d52401228d4
6
+ metadata.gz: 619279deb6f205b3dd6da7c3c1ddfe33a39b5f80a0083b2220d6eaee62942f340dde67d65cc719ce0e45afdcadb34bf4fe9f3a523492fce6b5361510c777fa26
7
+ data.tar.gz: 86cb47fc93d85e10c8226c65b44f3f8cac1d01623d1c60f0cf2253c75b14f9cebef88d5eb8b6d17654b7aad595480cd8485bd755dad748fc3079cad6dd4d36be
@@ -0,0 +1,28 @@
1
+ @zt_module.directive 'ztAutoCheckbox', ['$timeout', ($timeout) ->
2
+ directive_object =
3
+ restrict: 'E'
4
+ transclude: true
5
+ scope:
6
+ ztItem: '=?'
7
+ ztField: '@'
8
+ controller: ($scope) ->
9
+ $scope.status = 0
10
+ $scope.getItem = ->
11
+ $scope.ztItem or $scope.$parent.item
12
+ $scope.doPerformUpdate = ->
13
+ $scope.status = 1
14
+ ct1 = $scope.ct1 = ($scope.ct1 + 1 || 0)
15
+ $scope.getItem().save()
16
+ .then ->
17
+ if ct1 == $scope.ct1 and $scope.status = 1
18
+ $scope.status = 2
19
+ ct2 = $scope.ct2 = ($scope.ct2 + 1 || 0)
20
+ $timeout ->
21
+ if ct2 == $scope.ct2 and $scope.status == 2
22
+ $scope.status = 0
23
+ ,2000
24
+ .catch ->
25
+ $scope.getItem().revert()
26
+ $scope.status = 3
27
+ templateUrl: "zt-auto-checkbox.html"
28
+ ]
@@ -0,0 +1,54 @@
1
+ @zt_module.directive 'ztAutoTextbox', ->
2
+ directive_object =
3
+ restrict: 'E'
4
+ transclude: false
5
+ scope:
6
+ ztItem: '=?'
7
+ ztField: '@'
8
+ ztUpdateSuccess: '&?'
9
+ link: (scope, elem, attr) ->
10
+ unless typeof scope.ztItem == "undefined"
11
+ scope.$watch (scope) ->
12
+ scope.ztItem
13
+ , ->
14
+ scope.revertLocal() if scope.ztItem
15
+ else
16
+ scope.$parent.$watch (parent_scope) ->
17
+ parent_scope.item
18
+ , ->
19
+ scope.revertLocal() if scope.$parent.item
20
+ scope.label_visible = (elem.attr('class').indexOf('zt-inline') == -1)
21
+ controller: ['$timeout', '$scope', ($timeout, $scope) ->
22
+ $scope.status = 0
23
+ $scope.getItem = ->
24
+ $scope.ztItem or $scope.$parent.item
25
+ $scope.inputTextChange = ->
26
+ $scope.status = 1
27
+ ct1 = $scope.ct1 = ($scope.ct1 + 1 || 0)
28
+ $timeout ->
29
+ if ct1 == $scope.ct1
30
+ $scope.completeEditing()
31
+ ,1000
32
+ $scope.revertLocal = ->
33
+ $scope.field_value = $scope.getItem().copy[$scope.ztField]
34
+ $scope.status = 0
35
+ $scope.completeEditing = ->
36
+ $scope.status = 2
37
+ ct2 = $scope.ct2 = ($scope.ct2 + 1 || 0)
38
+ $scope.getItem().copy[$scope.ztField] = $scope.field_value
39
+ $scope.getItem().save()
40
+ .then ->
41
+ if ct2 == $scope.ct2 and $scope.status == 2
42
+ $scope.status = 3
43
+ ct3 = $scope.ct3 = ($scope.ct3 + 1 || 0)
44
+ $timeout ->
45
+ if ct3 == $scope.ct3 and $scope.status == 3
46
+ $scope.status = 0
47
+ if $scope.ztUpdateSuccess?
48
+ $scope.ztUpdateSuccess()
49
+ ,2000
50
+ .catch ->
51
+ $scope.status = 4
52
+ ]
53
+ templateUrl: "zt-auto-textbox.html"
54
+
@@ -0,0 +1,52 @@
1
+ @zt_module.directive 'ztTextbox', ->
2
+ directive_object =
3
+ restrict: 'E'
4
+ transclude: true
5
+ scope:
6
+ ztItem: '=?'
7
+ ztField: '@'
8
+ ztUpdateSuccess: '&?'
9
+ link: (scope, elem, attr) ->
10
+ unless typeof scope.ztItem == "undefined"
11
+ scope.$watch (scope) ->
12
+ scope.ztItem
13
+ , ->
14
+ scope.revertLocal() if scope.ztItem
15
+ else
16
+ scope.$parent.$watch (parent_scope) ->
17
+ parent_scope.item
18
+ , ->
19
+ scope.revertLocal() if scope.$parent.item
20
+ controller: ['$timeout', '$scope', ($timeout, $scope) ->
21
+ $scope.status = 0
22
+ $scope.getItem = ->
23
+ $scope.ztItem or $scope.$parent.item
24
+ $scope.startEditing = ->
25
+ $scope.status = 3 if $scope.status == 0
26
+ $scope.revertLocal = ->
27
+ $scope.field_value = $scope.getItem().copy[$scope.ztField]
28
+ $scope.status = 0
29
+ $scope.cancelEditing = ->
30
+ $scope.getItem().revert()
31
+ $scope.revertLocal()
32
+ $scope.completeEditing = ->
33
+ $scope.status = 2
34
+ ct1 = $scope.ct1 = ($scope.ct1 + 1 || 0)
35
+ $scope.getItem().copy[$scope.ztField] = $scope.field_value
36
+ $scope.getItem().save()
37
+ .then ->
38
+ if ct1 == $scope.ct1 and $scope.status == 2
39
+ $scope.status = 1
40
+ ct2 = $scope.ct2 = ($scope.ct2 + 1 || 0)
41
+ $timeout ->
42
+ if ct2 == $scope.ct2 and $scope.status == 1
43
+ if $scope.ztUpdateSuccess?
44
+ $scope.ztUpdateSuccess()
45
+ $scope.status = 0
46
+ ,2000
47
+ .catch ->
48
+ $scope.status = 4
49
+
50
+ ]
51
+ templateUrl: "zt-textbox.html"
52
+
@@ -0,0 +1,45 @@
1
+ @zt_module.directive 'ztfButton', ->
2
+ ret =
3
+ restrict: 'AE' # also possible class C
4
+ transclude: true # set to false if ignoring content
5
+ scope:
6
+ cmd: '&ztfCommit' # isolate scope of a function, passed as a value
7
+ # of the attribute with the name of the directive
8
+ disabled: '=' # isolate scope of a model (both ways), passed with an
9
+ # attribute disabled="XXX", where XXX is a variable of
10
+ # the scope
11
+ glyph: '@' # isolate scope of a variable (in only), passed with
12
+ # an attribute disabled="123"
13
+ link: (scope, elem, attrs) ->
14
+ s while !(s = (s || scope).$parent).isZtfForm
15
+ scope.form = s
16
+ scope.action = 'commit' if isDefined(attrs.commit)
17
+ scope.action = 'cancel' if isDefined(attrs.cancel)
18
+ scope.action = 'edit' if isDefined(attrs.edit)
19
+ scope.action = 'add' if isDefined(attrs.add)
20
+ scope.action = 'delete' if isDefined(attrs.delete)
21
+ scope.action = attrs.action if isDefined(attrs.action)
22
+ scope.title_given = elem.find('span').length && elem.find('span')[0].children.length;
23
+ if isDefined(elem.attr('zt-icon'))
24
+ scope.useIcon = true
25
+ scope.iconClass = if elem.attr('zt-icon') != ""
26
+ elem.attr('zt-icon')
27
+ else if isDefined(attrs.commit)
28
+ 'glyphicon-floppy-disk'
29
+ else if isDefined(attrs.cancel)
30
+ 'glyphicon-remove'
31
+ else if isDefined(attrs.edit)
32
+ 'glyphicon-pencil'
33
+ else if isDefined(attrs.add)
34
+ 'glyphicon-plus'
35
+ else if isDefined(attrs.delete)
36
+ 'glyphicon-trash'
37
+ scope.hideMe = ->
38
+ if isDefined(attrs.commit) or isDefined(attrs.cancel) or isDefined(attrs.add) or isDefined(attrs.delete)
39
+ !scope.form.editable
40
+ else if isDefined(attrs.edit)
41
+ scope.form.editable
42
+ controller: ($scope) ->
43
+ $scope.index = ->
44
+ if isDefined($scope.$parent.$parent.$index) then $scope.$parent.$parent.$index else null
45
+ templateUrl: "ztf-button.html"
@@ -0,0 +1,28 @@
1
+ @zt_module.directive 'ztfCheckbox', ->
2
+ directive_object =
3
+ restrict: 'E'
4
+ transclude: true
5
+ scope:
6
+ ztField: '@'
7
+ link: (scope, elem, attr) ->
8
+ s while !(s = (s || scope).$parent).hasOwnProperty('isZtfForm')
9
+ scope.form = s
10
+ controller: ($scope) ->
11
+ $scope.index = ->
12
+ if isDefined($scope.$parent.$parent.$index) then $scope.$parent.$parent.$index else null
13
+ $scope.itemCopy = ->
14
+ $scope.form.itemCopy($scope.ztField, $scope.index())
15
+ $scope.revertLocal = ->
16
+ $scope.form.revertField($scope.ztField, $scope.index())
17
+ $scope.fieldModified = ->
18
+ $scope.form.fieldModified($scope.ztField, $scope.index())
19
+ $scope.fieldUpdating = ->
20
+ $scope.form.fieldUpdating($scope.ztField, $scope.index())
21
+ $scope.fieldError = ->
22
+ $scope.form.fieldError($scope.ztField, $scope.index())
23
+ $scope.fieldUpdated = ->
24
+ $scope.form.fieldUpdated($scope.ztField, $scope.index())
25
+ $scope.glyphTitle = ->
26
+ if $scope.form and $scope.itemCopy() and $scope.fieldError()
27
+ "Could not save changes. Click to revert."
28
+ templateUrl: "ztf-checkbox.html"
@@ -0,0 +1,71 @@
1
+ @zt_module.directive 'ztfForm', ['$timeout', ($timeout) ->
2
+ ret =
3
+ restrict: 'AE' # also possible class C
4
+ transclude: true # set to false if ignoring content
5
+ scope:
6
+ ztItem: '=?'
7
+ ztUpdateSuccess: '&?'
8
+ link: (scope, elem, attrs, ctrl, transclude) ->
9
+ scope.lockable = isDefined(attrs.lockable)
10
+ scope.editable = (scope.getItem() and scope.getItem().clientOnly) || !scope.lockable
11
+ controller: ($scope) ->
12
+ $scope.isZtfForm = true
13
+ $scope.isZtfSubform = false
14
+ $scope.updated_fields = []
15
+ $scope.error_fields = []
16
+ $scope.getItem = ->
17
+ $scope.ztItem or $scope.$parent.item
18
+ $scope.commit = ->
19
+ $scope.error_fields = []
20
+ $scope.updated_fields = []
21
+ $scope.updated_fields.push key for own key of $scope.getItem().data when $scope.getItem().data[key] != $scope.getItem().copy[key] and key[0] != '_'
22
+ $scope.updating = true
23
+ $scope.getItem().save()
24
+ .then ->
25
+ $scope.updating = false
26
+ if $scope.lockable
27
+ $scope.editable = false
28
+ $timeout ->
29
+ $scope.updated_fields = []
30
+ if $scope.ztUpdateSuccess?
31
+ $scope.ztUpdateSuccess()
32
+ ,2000
33
+ .catch ->
34
+ $scope.updating = false
35
+ $scope.error_fields = $scope.updated_fields
36
+ $scope.updated_fields = []
37
+ $scope.cancel = ->
38
+ $scope.getItem().copy = angular.copy($scope.getItem().data)
39
+ if $scope.lockable
40
+ $scope.editable = false
41
+ $scope.edit = ->
42
+ if $scope.lockable
43
+ $scope.editable = true
44
+ $scope.enable_button = (action) ->
45
+ if action in ['commit', 'cancel']
46
+ return $scope.editable
47
+ else if action == 'edit'
48
+ return !$scope.editable
49
+ $scope.show_button = (action) ->
50
+ if action in ['commit', 'cancel']
51
+ return $scope.editable
52
+ else if action == 'edit'
53
+ return !$scope.editable
54
+ $scope.itemCopy = (ztField, index) ->
55
+ throw "Form passed an index other than null, which is only allowed on subforms" if index
56
+ if $scope.getItem() then $scope.getItem().copy else null
57
+ $scope.revertField = (ztField, index) ->
58
+ $scope.getItem().copy[ztField] = $scope.getItem().data[ztField] unless $scope.fieldUpdating(ztField, index)
59
+ $scope.fieldModified = (ztField, index) ->
60
+ $scope.getItem() and if $scope.getItem().clientOnly
61
+ $scope.getItem().copy[ztField]
62
+ else
63
+ $scope.getItem().copy[ztField] != $scope.getItem().data[ztField]
64
+ $scope.fieldUpdating = (ztField, index) ->
65
+ $scope.updating and $scope.updated_fields.indexOf(ztField) > -1
66
+ $scope.fieldError = (ztField, index) ->
67
+ $scope.error_fields.indexOf(ztField) > -1 and $scope.fieldModified(ztField, index)
68
+ $scope.fieldUpdated = (ztField, index) ->
69
+ $scope.updated_fields.indexOf(ztField) > -1
70
+ templateUrl: "ztf-form.html"
71
+ ]
@@ -0,0 +1,73 @@
1
+ @zt_module.directive 'ztfSubform', ->
2
+ ret =
3
+ restrict: 'E' # also possible class C
4
+ transclude: true # set to false if ignoring content
5
+ scope:
6
+ ztField: '@'
7
+ ztTitle: '@?'
8
+ link: (scope, elem, attrs, ctrl, transclude) ->
9
+ s while !(s = (s || scope).$parent).hasOwnProperty('isZtfForm')
10
+ scope.form = s
11
+ scope.canAdd = isDefined(attrs.ztAdd)
12
+ scope.canDelete = isDefined(attrs.ztDelete)
13
+ scope.editable = scope.form.editable
14
+ scope.inline = isDefined(attrs.ztInline)
15
+ scope.form.$watch ->
16
+ scope.form.editable
17
+ , ->
18
+ scope.editable = scope.form.editable
19
+ controller: ($scope) ->
20
+ # this directive's scope is a 'form' for all underlying scopes.
21
+ # However, to this directive, 'form' is a parent form scope.
22
+ $scope.isZtfForm = true
23
+ $scope.isZtfSubform = true
24
+ $scope.superItem = ->
25
+ $scope.form.getItem()
26
+ $scope.subitems = ->
27
+ if $scope.superItem() then $scope.superItem().copy[$scope.ztField] else null
28
+ $scope.getItem = (index) ->
29
+ if $scope.subitems() then $scope.subitems()[index] else null
30
+ $scope.enable_button = (action) ->
31
+ if action in ['add', 'delete']
32
+ $scope.form.editable
33
+ else
34
+ false
35
+ $scope.show_button = (action) ->
36
+ if action in ['add', 'delete']
37
+ $scope.form.editable
38
+ else
39
+ false
40
+ $scope.fieldValue = (ztField, index, data) ->
41
+ if data
42
+ # when looking for the original field, first check if the copy field has the _index
43
+ if isDefined($scope.superItem().copy[$scope.ztField][index]._index)
44
+ _index = $scope.superItem().copy[$scope.ztField][index]._index
45
+ #this means this is one of originally fetched fields which DO have the data
46
+ #use that index, not the copy index
47
+ $scope.superItem().data[$scope.ztField][_index][ztField]
48
+ else
49
+ null
50
+ else
51
+ $scope.superItem().copy[$scope.ztField][index][ztField]
52
+ $scope.itemCopy = (ztField, index) ->
53
+ throw "Subform passed a null index, which is only allowed on top level forms" if index == null
54
+ $scope.getItem(index)
55
+ $scope.revertField = (ztSubField, index) ->
56
+ throw "Subform passed a null index, which is only allowed on top level forms" if index == null
57
+ $scope.superItem().copy[$scope.ztField][index][ztSubField] = $scope.fieldValue(ztSubField, index, true) unless $scope.fieldUpdating(ztSubField, index) or not $scope.fieldValue(ztSubField, index, true)
58
+ $scope.fieldModified = (ztSubField, index) ->
59
+ $scope.superItem() and if $scope.superItem().clientOnly
60
+ $scope.fieldValue(ztSubField, index, false)
61
+ else
62
+ $scope.fieldValue(ztSubField, index, false) != $scope.fieldValue(ztSubField, index, true)
63
+ $scope.fieldUpdating = (ztSubField, index) ->
64
+ $scope.form.updating and $scope.fieldUpdated(ztSubField, index)
65
+ $scope.fieldError = (ztSubField, index) ->
66
+ $scope.form.error_fields.indexOf("#{$scope.ztField}[#{index}].#{ztSubField}") > -1 and $scope.fieldModified(ztSubField, index)
67
+ $scope.fieldUpdated = (ztSubField, index) ->
68
+ $scope.form.updated_fields.indexOf("#{$scope.ztField}[#{index}].#{ztSubField}") > -1
69
+ $scope.add = ->
70
+ $scope.subitems().push new Object()
71
+ $scope.delete = (index) ->
72
+ $scope.subitems().splice(index, 1)
73
+ templateUrl: "ztf-subform.html"
@@ -0,0 +1,30 @@
1
+ @zt_module.directive 'ztfTextbox', ->
2
+ ret =
3
+ restrict: 'E'
4
+ transclude: false
5
+ scope:
6
+ ztField: '@'
7
+ ztLabel: '@'
8
+ link: (scope, elem, attr) ->
9
+ s while !(s = (s || scope).$parent).hasOwnProperty('isZtfForm')
10
+ scope.form = s
11
+ controller: ($scope) ->
12
+ $scope.index = ->
13
+ if isDefined($scope.$parent.$parent.$index) then $scope.$parent.$parent.$index else null
14
+ $scope.itemCopy = ->
15
+ $scope.form.itemCopy($scope.ztField, $scope.index())
16
+ $scope.revertLocal = ->
17
+ $scope.form.revertField($scope.ztField, $scope.index())
18
+ $scope.fieldModified = ->
19
+ $scope.form.fieldModified($scope.ztField, $scope.index())
20
+ $scope.fieldUpdating = ->
21
+ $scope.form.fieldUpdating($scope.ztField, $scope.index())
22
+ $scope.fieldError = ->
23
+ $scope.form.fieldError($scope.ztField, $scope.index())
24
+ $scope.fieldUpdated = ->
25
+ $scope.form.fieldUpdated($scope.ztField, $scope.index())
26
+ $scope.glyphTitle = ->
27
+ if $scope.form and $scope.itemCopy() and $scope.fieldError()
28
+ "Could not save changes. Click to revert."
29
+ templateUrl: "ztf-textbox.html"
30
+
@@ -0,0 +1,2 @@
1
+ String.prototype.capitalize = ->
2
+ return this.charAt(0).toUpperCase() + this.slice(1);
@@ -0,0 +1,156 @@
1
+ # Since there can be way too many documents, what we do try is to keep on client side aout 1000
2
+ # around the current one, whatever it is, or the midian one if more than one are active.
3
+ #
4
+ # Same principal might be used later for other types of objects, as long as they are
5
+ # ordered in some way. Documents are ordered always by a @identifier, which must be defined
6
+ # in the child service.
7
+ #
8
+ # This system is assumed to work with the following limits:
9
+ #
10
+ # - In the database, any kind of amount is possible, but oading will depend
11
+ # on that amount. Whatever it can be filtered or sorted on must be indexed.
12
+ #
13
+ # - What is retrieved is up to 1000 records (defined by @front_end_buffer_size),
14
+ # each not bigger than 1-5k, making it up to 1-5M. That should be transfered
15
+ # within a second.
16
+ #
17
+ # - What is shown should never be more than 20-50 record@
18
+
19
+
20
+
21
+ @zt_module.service 'ztBaseService', [
22
+ '$http', '$q',
23
+ ($http, $q) ->
24
+ @front_end_buffer_size = 200
25
+ @eagerness = 30
26
+ @page_size = 10
27
+ # Following is the key by which sorting is done
28
+ @front_end_buffer = null
29
+ @front_end_buffer_limit_low = null
30
+ @front_end_buffer_limit_high = null
31
+ @front_end_buffer_index_low = null
32
+ @front_end_buffer_index_high = null
33
+ @total_count = null
34
+ # Method 'item' return the item with given id or the first item available
35
+ # meaning, essentially, any item.
36
+ @item = (id) ->
37
+ if @front_end_buffer? and @front_end_buffer_limit_low <= id <= @front_end_buffer_limit_high
38
+ $q.when { item: @_find_item(id), total_count: @total_count }
39
+ else
40
+ me = this
41
+ @_reload_around_id(id)
42
+ .then ->
43
+ { item: me._find_item(id), total_count: me.total_count }
44
+ # Method relative returns item with given offset from current item
45
+ # Normally this would be used with -1 or 1.
46
+ @item_relative = (item, offset) ->
47
+ if @front_end_buffer? and @front_end_buffer_index_low <= item.data.index + offset <= @front_end_buffer_index_high
48
+ #eager loading
49
+ if (offset < 0 and @front_end_buffer_index_low + @eagerness > item.data.index + offset) or
50
+ (offset > 0 and item.data.index + offset > @front_end_buffer_index_high - @eagerness)
51
+ @_reload_by_index(item.data.index, offset)
52
+ $q.when { item: @_find_by_index(item.data.index + offset), total_count: @total_count }
53
+ else
54
+ me = this
55
+ @_reload_by_index(item.data.index, offset)
56
+ .then ->
57
+ { item: me._find_by_index(item.data.index + offset), total_count: me.total_count }
58
+ @page_items = (page_no, direction) ->
59
+ if @front_end_buffer? and @front_end_buffer_index_low <= (page_no - 1) * @page_size and page_no * @page_size<= @front_end_buffer_index_high
60
+ #eager loading
61
+ if @front_end_buffer_index_low + @eagerness > (page_no - 1) * @page_size or
62
+ page_no * @page_size > @front_end_buffer_index_high - @eagerness
63
+ @_reload_by_index((page_no - 1) * @page_size + @page_size / 2, 0)
64
+ $q.when { items: @_find_page_items(page_no), page_count: @_total_page_count() }
65
+ else
66
+ me = this
67
+ @_reload_by_index((page_no - 1) * @page_size + @page_size / 2, 0)
68
+ .then ->
69
+ { items: me._find_page_items(page_no), page_count: me._total_page_count() }
70
+ @range = (low_id, high_id) ->
71
+ null
72
+ @update = (item) ->
73
+ data = new Object()
74
+ data[@resource_name] = item.copy
75
+ $http.put "./#{@resource_url}/#{item.data._id.$oid}.json", data
76
+ @create = (item) ->
77
+ data = new Object()
78
+ data[@resource_name] = item.copy
79
+ $http.post "./#{@resource_url}.json", data
80
+ @newitem = ->
81
+ container = this
82
+ newly_created_item =
83
+ data: null
84
+ copy: {}
85
+ clientOnly: true
86
+ saved: false
87
+ save: ->
88
+ me = this
89
+ container.create(me)
90
+ .then ->
91
+ me.saved = true
92
+ revert: ->
93
+ throw "Cannot call revert on new object"
94
+ is_first: true
95
+ is_last: true
96
+ mynewitem =
97
+ item:
98
+ newly_created_item
99
+ if isDefined(@initialize_new_object)
100
+ @initialize_new_object(mynewitem.item.copy)
101
+ $q.when mynewitem
102
+ # private helpers
103
+ @_find_item = (id) ->
104
+ id = null if id == "undefined"
105
+ return item for item in @front_end_buffer when (not id?) or item.data[@identifier] == id
106
+ @_find_by_index = (index) ->
107
+ return item for item in @front_end_buffer when item.data.index == index
108
+ @_reload_around_id = (id) ->
109
+ id = null if id == "undefined"
110
+ me = this
111
+ $http.get("./#{@resource_url}.json?count=#{@front_end_buffer_size}" + (if id? then "&around=#{id}" else "" ))
112
+ .then (resp) ->
113
+ me._save_results(resp)
114
+ @_find_page_items = (page_no) ->
115
+ skipped = @front_end_buffer_index_low
116
+ @front_end_buffer.slice (page_no - 1) * @page_size - skipped,
117
+ page_no * @page_size - skipped
118
+ @_total_page_count = () ->
119
+ Math.trunc((@total_count + @page_size - 1) / @page_size)
120
+ @_reload_by_index = (index, offset) ->
121
+ me = this
122
+ $http.get("./#{@resource_url}.json?count=#{@front_end_buffer_size}&index=#{index}" + (if offset then "&offset=#{offset}" else "" ))
123
+ .then (resp) ->
124
+ me._save_results(resp)
125
+ @_save_results = (resp) ->
126
+ @front_end_buffer = []
127
+ container = this
128
+ for d, i in resp.data.list
129
+ # add indexes to each array
130
+ for own field of d when d[field] instanceof Array
131
+ for list_item, i2 in d[field]
132
+ list_item._index = i2
133
+ @front_end_buffer.push
134
+ data: d
135
+ copy: angular.copy(d)
136
+ save: ->
137
+ me = this
138
+ container.update(me)
139
+ .then ->
140
+ for own field of me.copy when me.copy[field] instanceof Array
141
+ for list_item, i2 in me.copy[field]
142
+ list_item._index = i2
143
+ me.data = angular.copy(me.copy)
144
+ revert: ->
145
+ this.copy = angular.copy(this.data)
146
+ is_first: i == 0
147
+ is_last: i == resp.data.list.length - 1
148
+ @front_end_buffer_limit_low = resp.data.list[0][@identifier]
149
+ @front_end_buffer_limit_high = resp.data.list[-1..][0][@identifier]
150
+ @front_end_buffer_index_low = resp.data.list[0].index
151
+ @front_end_buffer_index_high = resp.data.list[-1..][0].index
152
+ @total_count = resp.data.total_count
153
+ resp.data
154
+ @extends_to = (obj) ->
155
+ angular.copy(this, obj)
156
+ this]
@@ -0,0 +1,8 @@
1
+ .checkbox
2
+ %label(ng-class="{'text-success': status === 2, 'text-warning': status === 1, 'text-danger': status === 3}")
3
+ %input(type="checkbox" ng-model="getItem().copy[ztField]" ng-click="doPerformUpdate()")
4
+ %span(ng-transclude)
5
+ %i.glyphicon.glyphicon-ok.text-success(ng-show="status === 2")
6
+ %i.glyphicon.glyphicon-refresh.text-warning(ng-show="status === 1")
7
+ %i.glyphicon.glyphicon-warning-sign.text-danger(ng-show="status === 3" title="Could not save changes. Click icon to try again." ng-click="getItem().copy[ztField] = !getItem().copy[ztField]")
8
+
@@ -0,0 +1,5 @@
1
+ .form-group.has-feedback(ng-class="{'has-warning': status === 1 || status === 2, 'has-success': status === 3, 'has-error': status === 4}")
2
+ %label.control-label(ng-class="{'sr-only': !label_visible}") Tag name
3
+ %input.form-control(type="text" placeholder="New tag" ng-model="field_value" ng-change="inputTextChange()")
4
+ %i.form-control-feedback.glyphicon.glyphicon-warning-sign.text-danger(ng-show="status === 4" title="Could not save changes. Click error icon to retry!" ng-click="completeEditing()")
5
+ %i.form-control-feedback.glyphicon(ng-show="status === 3 || status === 2" ng-class="{'text-success': status === 3, 'glyphicon-refresh': status === 2, 'text-warning': status === 2, 'glyphicon-ok': status === 3}")
@@ -0,0 +1,11 @@
1
+ .form-group.has-feedback(ng-class="{'has-warning': getItem().copy[ztField] != field_value || status == 2, 'has-success': status == 1, 'has-error': status === 4}")
2
+ %span(ng-transclude ng-hide="status > 1")
3
+ %span.text-muted(ng-hide="status > 1" ng-click="startEditing()") (edit)
4
+ %span.glyphicon.glyphicon-ok.text-success(ng-show="status == 1")
5
+ .input-group(ng-show="status > 1")
6
+ %input.form-control(ng-model="field_value" )
7
+ %span.input-group-addon(ng-click="cancelEditing()")
8
+ %span.glyphicon.glyphicon-remove
9
+ %span.input-group-addon(ng-click="completeEditing()")
10
+ %span.glyphicon.glyphicon-warning-sign.text-danger(ng-show="status == 4" title="Could not save changes. Click to try again.")
11
+ %span.glyphicon(ng-class="{'text-success': status == 1, 'glyphicon-refresh': status == 2, 'text-warning': status == 2, 'glyphicon-ok': status != 2}")
@@ -0,0 +1,4 @@
1
+ %button.ztf-button.btn.btn-default(ng-click="form[action](index())" ng-disabled="!form.enable_button(action)" ng-hide="hideMe()")
2
+ %span(ng-if="!useIcon"ng-transclude)
3
+ %span(ng-if="!title_given && !useIcon") {{action.capitalize()}}
4
+ %i.glyphicon(ng-if="useIcon" ng-class="iconClass")
@@ -0,0 +1,11 @@
1
+ .ztf-checkbox.checkbox
2
+ %span(ng-hide="form.editable" ng-class="{'text-success': fieldUpdated()}")
3
+ %i.glyphicon(ng-class="{'glyphicon-ok': form.getItem().copy[ztField] === true, 'glyphicon-remove': form.getItem().copy[ztField] === false, 'text-success': form.getItem().copy[ztField] === true, 'text-danger': form.getItem().copy[ztField] === false}")
4
+ %span(ng-transclude)
5
+ %i.glyphicon.glyphicon-saved.text-success(ng-show="fieldUpdated()")
6
+ %label(ng-show="form.editable" ng-class="{'text-warning': fieldModified(), 'text-danger': fieldError(),'bg-red': fieldModified(), 'bg-red': fieldError()}")
7
+ %input(type="checkbox" ng-model="form.getItem().copy[ztField]")
8
+ %span(ng-transclude)
9
+ %i.glyphicon.glyphicon-refresh.text-warning(ng-show="fieldUpdating()")
10
+ %i.glyphicon.glyphicon-warning-sign.text-danger(ng-show="fieldError()" title="{{glyphTitle()}}")
11
+
@@ -0,0 +1,2 @@
1
+ %form.ztf-form
2
+ %span(ng-transclude)
@@ -0,0 +1,9 @@
1
+ .ztf-subitems
2
+ %h4(ng-if="ztTitle") {{ztTitle}}
3
+ .ztf-subitem(style="float: left;clear: both;display: block;" ng-repeat="item in subitems()")
4
+ %form(role="form" ng-class="{'form-inline': inline}")
5
+ %ztf-button(style="float: right;clear: none;display: inline;" delete ng-if="canDelete" zt-hide zt-icon zt-inline)
6
+ %span(style="float: right;clear: none;display: inline;" ng-transclude)
7
+ .clearfix
8
+ %ztf-button(add ng-if="canAdd" zt-hide zt-icon)
9
+
@@ -0,0 +1,12 @@
1
+ .form-group.has-feedback()
2
+ %label(ng-if="isDefined(ztLabel)" ng-class="{'text-success': fieldUpdated()}")
3
+ {{ztLabel}}:
4
+ .input-wrapper
5
+ .input-group(ng-show="form.editable"ng-class="{'has-warning': fieldModified(), 'has-error': fieldError()}")
6
+ %input.form-control(ng-model="itemCopy()[ztField]" )
7
+ %span.input-group-addon
8
+ %i.glyphicon(ng-class="{'glyphicon-remove': !fieldError() && !fieldUpdating(),'glyphicon-refresh': fieldUpdating(), 'text-warning': fieldUpdating(), 'glyphicon-warning-sign': fieldError()}" ng-click="revertLocal()" title="{{glyphTitle()}}")
9
+ %span(ng-hide="form.editable")
10
+ {{itemCopy()[ztField]}}
11
+ %i.glyphicon.glyphicon-saved.text-success(ng-show="fieldUpdated()")
12
+
data/bin/zwr CHANGED
@@ -78,7 +78,7 @@ when 'new'
78
78
  puts "You are in a git repo, and that is not good!"
79
79
  else
80
80
  cmd = <<-CMD.gsub /^ *$\n/, ''
81
- rails new #{ARGV[1]} --skip-bundle --skip-spring
81
+ rails new #{ARGV[1]} #{"--skip-bundle" unless @options[:bundle]} --skip-spring
82
82
  #{"--skip-active-record" if not @options[:activerecord]}
83
83
  -m #{File.expand_path('../../lib/zwr/app_template.rb', __FILE__)}
84
84
  #{"use-mongoid" if @options[:mongoid]}
@@ -86,7 +86,7 @@ when 'new'
86
86
  #{"use-devise" if @options[:devise]}
87
87
  CMD
88
88
  putsv " \033[35mexec\033[0m #{cmd.strip}"
89
- exec(cmd.gsub(/\r/," ").gsub(/\n/," ").gsub(/ /," "))
89
+ exec(cmd.gsub(/\r/," ").gsub(/\n/," ").gsub(/\ \ +/," "))
90
90
  end
91
91
  when 'deploy'
92
92
  if ARGV.length < 2
@@ -5,7 +5,7 @@ module Zwr
5
5
  ang_file_name = file_name.gsub("_","-")
6
6
  dir_class = file_name.gsub("-","_").camelize(:lower)
7
7
  create_file "app/assets/javascripts/directives/#{ang_file_name}.js.coffee", <<-FILE.strip_heredoc
8
- @#{application_name}.directive '#{dir_class}', ->
8
+ @#{application_name}.directive '#{dir_class}', ['$timeout', ($timeout) ->
9
9
  ret =
10
10
  restrict: 'AE' # also possible class C
11
11
  transclude: true # set to false if ignoring content
@@ -17,7 +17,25 @@ module Zwr
17
17
  # the scope
18
18
  glyph: '@' # isolate scope of a variable (in only), passed with
19
19
  # an attribute disabled="123"
20
- templateUrl: "#{ang_file_name}.html"
20
+ link: (scope, elem, attr) ->
21
+ scope.$watch (scope) ->
22
+ scope.ztItem
23
+ , ->
24
+ scope.revertLocal() if scope.ztItem
25
+ scope.$watch () ->
26
+ element[0].focus() if scope.focusMe == 'true'
27
+ plunker = ->
28
+ $timeout ->
29
+ scope.focuschange = !scope.focuschange
30
+ plunker()
31
+ ,1000
32
+ plunker()
33
+ controller: ($scope) ->
34
+ $scope.status = 0
35
+ $scope.getItem = ->
36
+ $scope.myItem or $scope.$parent.item
37
+ templateUrl: "#{ang_file_name}.html"
38
+ ]
21
39
  FILE
22
40
  create_file "app/assets/javascripts/templates/#{ang_file_name}.html.haml", <<-FILE.strip_heredoc
23
41
  .#{ang_file_name}
@@ -11,6 +11,9 @@ use_angular = @args.include? 'use-angular'
11
11
  use_mongoid = @args.include? 'use-mongoid'
12
12
  use_devise = @args.include? 'use-devise'
13
13
 
14
+ gsub_file "Gemfile","# gem 'therubyracer'", "gem 'therubyracer'"
15
+
16
+
14
17
  gem 'zwr'
15
18
  gem 'bootstrap-sass', '~> 3.2.0'
16
19
  gem 'bootstrap_form'
@@ -58,6 +61,9 @@ gem 'tzinfo', platforms: [:mingw, :mswin, :x64_mingw]
58
61
 
59
62
  if use_devise
60
63
  gem 'devise', '~> 3.3.0'
64
+ unless use_mongoid
65
+ run 'bundle install --quiet'
66
+ end
61
67
  generate 'devise:install'
62
68
  generate :scaffold, 'User', 'name:string', 'email:string',
63
69
  'password:string', 'password_confirmation:string', 'admin:boolean'
@@ -131,14 +137,11 @@ initializer 'zwr.rb', <<-FILE.strip_heredoc
131
137
 
132
138
  file 'db/seeds/.keep'
133
139
 
134
-
140
+ run 'bundle install --quiet'
135
141
 
136
142
  rake 'zwr:install'
137
143
  rake 'db:migrate'
138
144
 
139
- unless use_mongoid
140
- run 'bundle install --quiet'
141
- end
142
145
 
143
146
  # Git commands should be the last so that they catch all the files!
144
147
  git init: '-q'
@@ -1,9 +1,9 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'zwr'
3
- s.version = '0.1.6'
4
- s.date = '2014-11-17'
3
+ s.version = '0.1.7'
4
+ s.date = '2015-01-06'
5
5
  s.summary = "All the Zwr needs"
6
- s.description = "A gem in which I jam what I commonly use."
6
+ s.description = "the livings that fiteth for a gorge bellum."
7
7
  s.author = "Zeljko"
8
8
  s.email = 'zeljko@zwr.fi'
9
9
  s.files = `git ls-files`.split("\n") - %w(.rvmrc .gitignore)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zwr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zeljko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-17 00:00:00.000000000 Z
11
+ date: 2015-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -30,7 +30,7 @@ dependencies:
30
30
  - - '>='
31
31
  - !ruby/object:Gem::Version
32
32
  version: '3.1'
33
- description: A gem in which I jam what I commonly use.
33
+ description: the livings that fiteth for a gorge bellum.
34
34
  email: zeljko@zwr.fi
35
35
  executables:
36
36
  - zwr
@@ -48,12 +48,30 @@ files:
48
48
  - app/assets/images/logo_transparent.png
49
49
  - app/assets/javascripts/controllers/.keep
50
50
  - app/assets/javascripts/directives/.keep
51
+ - app/assets/javascripts/directives/zt-auto-checkbox.js.coffee
52
+ - app/assets/javascripts/directives/zt-auto-textbox.js.coffee
53
+ - app/assets/javascripts/directives/zt-textbox.js.coffee
54
+ - app/assets/javascripts/directives/ztf-button.js.coffee
55
+ - app/assets/javascripts/directives/ztf-checkbox.js.coffee
56
+ - app/assets/javascripts/directives/ztf-form.js.coffee
57
+ - app/assets/javascripts/directives/ztf-subform.js.coffee
58
+ - app/assets/javascripts/directives/ztf-textbox.js.coffee
51
59
  - app/assets/javascripts/includes/.keep
52
60
  - app/assets/javascripts/includes/angular-local-storage.js
53
61
  - app/assets/javascripts/includes/xml2json.js
62
+ - app/assets/javascripts/includes/zwr.js.coffee
54
63
  - app/assets/javascripts/services/.keep
64
+ - app/assets/javascripts/services/zt-base-service.js.coffee
55
65
  - app/assets/javascripts/templates/.keep
56
66
  - app/assets/javascripts/templates/404.html
67
+ - app/assets/javascripts/templates/zt-auto-checkbox.html.haml
68
+ - app/assets/javascripts/templates/zt-auto-textbox.html.haml
69
+ - app/assets/javascripts/templates/zt-textbox.html.haml
70
+ - app/assets/javascripts/templates/ztf-button.html.haml
71
+ - app/assets/javascripts/templates/ztf-checkbox.html.haml
72
+ - app/assets/javascripts/templates/ztf-form.html.haml
73
+ - app/assets/javascripts/templates/ztf-subform.html.haml
74
+ - app/assets/javascripts/templates/ztf-textbox.html.haml
57
75
  - app/assets/javascripts/zwr.js.coffee
58
76
  - app/assets/stylesheets/zwr.css.scss.erb
59
77
  - bin/zwr
@@ -99,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
117
  version: '0'
100
118
  requirements: []
101
119
  rubyforge_project:
102
- rubygems_version: 2.2.2
120
+ rubygems_version: 2.4.3
103
121
  signing_key:
104
122
  specification_version: 4
105
123
  summary: All the Zwr needs