angular-table 0.0.2 → 0.0.3

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: 9959d337ca7442e3599ada034d31775ecfe651ec
4
- data.tar.gz: 836895bf84471fb35409242cd38ef99baad1f247
3
+ metadata.gz: 0300b2bec8da95a7c4f5bb5b8355f49dad326d18
4
+ data.tar.gz: 68aee2657f079eddb91d28480908c2f258b9032d
5
5
  SHA512:
6
- metadata.gz: e8989ce7f47abf876445271e23325afb5afcd316de6e2a92270b3cc489cc0d6b8fd274e22431f1179437c2dd04767cf09f0545d17b3878af8a5c99e5bdfc8251
7
- data.tar.gz: 9fddb710dfe10caf667949094061b1904012859f080266abbf045aa0c9f922914442a5dda0e14ffa3e3f1573689f7001f58089f91cf65236def80a0356716caf
6
+ metadata.gz: 46a472c4ddb98017d75f3d3a8aa892f8c4db07edb7ae8c78fdf313ae78b3ef6df215513f7de83b714de8d937e419d8ff3367ed3393f4148dd0207ff378b45622
7
+ data.tar.gz: a2a270d4de0e8d5b8aa2a7807fef71a3faffcbd6df600c87bfe91c3680f06613ea3412105d1b6df4f6c0d7e631d58bea10a90a4bcc17ede1220e35ef288c13f7
@@ -1,3 +1,3 @@
1
1
  module AngularTable
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -23,41 +23,38 @@ angular.module("angular-table").service "attributeExtractor", () ->
23
23
  angular.module("angular-table").directive "atTable", ["attributeExtractor", (attributeExtractor) ->
24
24
 
25
25
  capitaliseFirstLetter = (string) ->
26
- string.charAt(0).toUpperCase() + string.slice(1)
27
-
28
- constructHeader = (element) ->
29
- thead = element.find "thead"
30
-
31
- if thead[0]
32
- tr = thead.find "tr"
33
- existing_ths = {}
34
- for th in tr.find "th"
35
- th = angular.element(th)
36
- existing_ths[th.attr("attribute")] = th.html()
37
-
38
- tr.remove()
39
- tr = $("<tr></tr>")
40
-
41
- tds = element.find("td")
42
- for td in tds
43
- td = angular.element(td)
44
- attribute = attributeExtractor.extractAttribute(td)
45
- th = $("<th style='cursor: pointer; -webkit-user-select: none;'></th>")
46
- title = existing_ths[attribute] || capitaliseFirstLetter(attributeExtractor.extractTitle(td))
47
- th.html("#{title}")
48
-
49
- sortable = td[0].attributes.sortable || attributeExtractor.isSortable(td.attr("class"))
50
- if sortable
51
- th.attr("ng-click", "predicate = '#{attribute}'; descending = !descending;")
52
- icon = angular.element("<i style='margin-left: 10px;'></i>")
53
- icon.attr("ng-class", "getSortIcon('#{attribute}')")
54
- th.append(icon)
55
-
56
- width = attributeExtractor.extractWidth(td.attr("class"))
57
- th.attr("width", width)
58
- tr.append(th)
59
-
60
- thead.append tr
26
+ if string then string.charAt(0).toUpperCase() + string.slice(1) else ""
27
+
28
+
29
+ constructHeader = (thead, tds) ->
30
+ tr = thead.find "tr"
31
+ existingThMarkup = {}
32
+ for th in tr.find "th"
33
+ th = angular.element(th)
34
+ existingThMarkup[th.attr("attribute")] = th.html()
35
+
36
+ tr.remove()
37
+ tr = angular.element("<tr></tr>")
38
+
39
+ for td in tds
40
+ td = angular.element(td)
41
+ attribute = attributeExtractor.extractAttribute(td)
42
+ th = angular.element("<th style='cursor: pointer;'></th>")
43
+ title = existingThMarkup[attribute] || capitaliseFirstLetter(attributeExtractor.extractTitle(td))
44
+ th.html("#{title}")
45
+
46
+ sortable = td[0].attributes.sortable || attributeExtractor.isSortable(td.attr("class"))
47
+ if sortable
48
+ th.attr("ng-click", "predicate = '#{attribute}'; descending = !descending;")
49
+ icon = angular.element("<i style='margin-left: 10px;'></i>")
50
+ icon.attr("ng-class", "getSortIcon('#{attribute}')")
51
+ th.append(icon)
52
+
53
+ width = attributeExtractor.extractWidth(td.attr("class"))
54
+ th.attr("width", width)
55
+ tr.append(th)
56
+
57
+ thead.append tr
61
58
 
62
59
  validateInput = (attributes) ->
63
60
  if attributes.pagination and attributes.list
@@ -72,8 +69,11 @@ angular.module("angular-table").directive "atTable", ["attributeExtractor", (att
72
69
  tbody
73
70
 
74
71
 
72
+ orderByExpression = "| orderBy:predicate:descending"
73
+ limitToExpression = "| limitTo:fromPage() | limitTo:toPage()"
74
+
75
75
  StandardSetup = (attributes) ->
76
- @repeatString = "item in #{attributes.list} | orderBy:predicate:descending"
76
+ @repeatString = "item in #{attributes.list} #{orderByExpression}"
77
77
  @compile = (element, attributes, transclude) ->
78
78
  setupTr element, @repeatString
79
79
 
@@ -81,7 +81,15 @@ angular.module("angular-table").directive "atTable", ["attributeExtractor", (att
81
81
  return
82
82
 
83
83
  PaginationSetup = (attributes) ->
84
- @repeatString = "item in #{attributes.pagination}.list | limitTo:fromPage() | limitTo:toPage() | orderBy:predicate:descending"
84
+
85
+ sortContext = attributes.sortContext || "global"
86
+
87
+ if sortContext == "global"
88
+ @repeatString = "item in #{attributes.pagination}.list #{orderByExpression} #{limitToExpression}"
89
+ else if sortContext == "page"
90
+ @repeatString = "item in #{attributes.pagination}.list #{limitToExpression} #{orderByExpression} "
91
+ else
92
+ throw "Invalid sort-context: #{sortContext}."
85
93
 
86
94
  @compile = (element, attributes, transclude) ->
87
95
  tbody = setupTr element, @repeatString
@@ -90,7 +98,7 @@ angular.module("angular-table").directive "atTable", ["attributeExtractor", (att
90
98
  tds = element.find("td")
91
99
  tdString = ""
92
100
  for td in tds
93
- tdString += "<td>{{item}}&nbsp;</td>"
101
+ tdString += "<td>&nbsp;</td>"
94
102
 
95
103
  fillerTr = angular.element("<tr>#{tdString}</tr>")
96
104
  fillerTr.attr("ng-repeat", "item in #{attributes.pagination}.getFillerArray() ")
@@ -120,7 +128,11 @@ angular.module("angular-table").directive "atTable", ["attributeExtractor", (att
120
128
  scope: true
121
129
  compile: (element, attributes, transclude) ->
122
130
  setup = createSetup attributes
123
- constructHeader(element)
131
+
132
+ thead = element.find "thead"
133
+ tds = element.find "td"
134
+ constructHeader(thead, tds) if thead[0]
135
+
124
136
  setup.compile(element, attributes, transclude)
125
137
  {
126
138
  post: ($scope, $element, $attributes) ->
@@ -196,7 +208,6 @@ angular.module("angular-table").directive "atPagination", ["attributeExtractor",
196
208
  else
197
209
  []
198
210
 
199
-
200
211
  $scope.goToPage = (page) ->
201
212
  page = Math.max(0, page)
202
213
  page = Math.min($scope.numberOfPages - 1, page)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: angular-table
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Mueller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-17 00:00:00.000000000 Z
11
+ date: 2013-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler