initial github commit

This commit is contained in:
2017-12-21 11:42:41 +01:00
commit a57548c7da
209 changed files with 3841 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
dateSort = (date_a, date_b) ->
if date_a
a = if date_a.toISOString then date_a.toISOString() else date_a
else
a = null
if date_b
b = if date_b.toISOString then date_b.toISOString() else date_b
else
b = null
Ember.compare a, b
create_date_sort = (attribute) ->
(object_a, object_b) ->
dateSort object_a.get(attribute), object_b.get(attribute)
export { create_date_sort }
export default dateSort
+10
View File
@@ -0,0 +1,10 @@
getMaxSuffix = (array) ->
max = 0
return 0 unless array
array.forEach (element)->
return unless element
max = Math.max(match[0], max) if match = String(element).match /\d+$/
max
window.get_max_suffix = getMaxSuffix # make globally available
export default getMaxSuffix
+11
View File
@@ -0,0 +1,11 @@
# based on https://github.com/alisdair/horses-and-chickens
import Ember from 'ember'
export default (attribute) ->
Ember.computed attribute,
get: ->
@get(attribute).toString()
set: (key, value) ->
@set(attribute, parseInt(value, 10))
return value
+46
View File
@@ -0,0 +1,46 @@
mapSum = (target, property) ->
Ember.computed "#{target}.@each.#{property}", ->
return 0 unless ary_result = @get(target).mapBy(property)
return 0 unless ary_result.length
ary_result.reduce( ((sum, item) -> sum + item), 0)
mapFilter = (target, property, filter_by_key) ->
Ember.computed "#{target}.@each.#{property}", filter_by_key, ->
@get(target).filterBy(property, @get(filter_by_key))
mapHasMany = (target, has_many_relation) ->
Ember.computed "#{target}.@each.#{has_many_relation}", ->
result = Ember.A()
Ember.RSVP.all(@get(target).mapBy(has_many_relation)).then (targets_has_many_associations) ->
Ember.run ->
targets_has_many_associations.forEach (target_has_many_records) ->
result.pushObjects target_has_many_records.toArray()
result
mapMany = (target, many_attribute) ->
Ember.computed "#{target}.@each.#{many_attribute}", ->
result = Ember.A()
Ember.run =>
targets = @get(target)
if Ember.isArray(targets)
targets.forEach (record) ->
result.pushObjects record.get(many_attribute)
else
targets.then (records) ->
records.forEach (record) ->
result.pushObjects record.get(many_attribute)
result
mapMax = (target, property, options={}) ->
Ember.computed "#{target}.@each.#{property}", ->
return 0 unless ary_result = @get(target).mapBy(property)
return 0 unless ary_result.length
ary_result.reduce (max, item) ->
Math.max(max, item)
, -Infinity
export { mapSum, mapFilter, mapHasMany, mapMany, mapMax }
export default Ember.Object.create
mapSum: mapSum
mapFilter: mapFilter
mapHasMany: mapHasMany
+12
View File
@@ -0,0 +1,12 @@
# This is an objects merge helper but in stead of
# mergin into the first object, it merges into the last object.
# This is a lot safer and better in coffeescript environments, since the
# last argument is the indented subject(focus) of configuration.
# Since the attributes of these have prevalence, this merger comes last
# in the used Ember.assign
mergeObjects = (objects..., target) ->
result = {}
Ember.assign result, objects..., target
result
window.merge_objects = mergeObjects
export default mergeObjects
+17
View File
@@ -0,0 +1,17 @@
export default Ember.Object.create
# go from string:
# 19, 21-27, 98-101
# to
# [19,21,22,23,24,25,26,27,98,99,100,101]
parse: (identifier) ->
ids = []
return ids unless identifier
String(identifier).replace(/\s/g, '').split(',').forEach (id_spec) ->
[id_start, id_end] = id_spec.split('-')
id_start = parseInt(id_start)
if id_end
range_result = [id_start..id_end]
ids = ids.concat range_result
else
ids.push id_start
ids
+12
View File
@@ -0,0 +1,12 @@
sortNumeric = (target, keys...) ->
Ember.computed.sort target, (a, b) ->
[int_a, int_b] = [parseInt(a.get(keys[0])), parseInt(b.get(keys[0]))]
if int_a > int_b
1
else if int_a < int_b
-1
else
0
export { sortNumeric }
export default sortNumeric