-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements to behaviors/spreadsheet-select
- Loading branch information
Pierre-Luc Carmel Biron
committed
Mar 11, 2017
1 parent
8d52949
commit 48eed45
Showing
15 changed files
with
917 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
import Ember from 'ember'; | ||
|
||
const { Evented, on, run } = Ember; | ||
|
||
export default Ember.Object.extend(Evented, { | ||
|
||
// passed-in | ||
a: null, // the default anchor point | ||
b: null, // the other point | ||
anchorIsB: false, | ||
anchorAdjustment: 0, | ||
|
||
/* | ||
anchor: Ember.computed('a', 'b', 'anchorIsB', function() { | ||
return this.get('anchorAdjustment') + (this.get('anchorIsB') ? this.get('b') : this.get('a')); | ||
}), | ||
other: Ember.computed('a', 'b', 'anchorIsB', function() { | ||
return this.get('anchorIsB') ? this.get('a') : this.get('b'); | ||
}), | ||
*/ | ||
|
||
realA: Ember.computed('anchorIsB', 'a', 'anchorAdjustment', { | ||
get() { | ||
let a = this.get('a'); | ||
return this.get('anchorIsB') ? a : a + this.get('anchorAdjustment'); | ||
}, | ||
set(key, value) { | ||
this.set('a', this.get('anchorIsB') ? value : value - this.get('anchorAdjustment')); | ||
return value; | ||
} | ||
}), | ||
|
||
realB: Ember.computed('anchorIsB', 'b', 'anchorAdjustment', { | ||
get() { | ||
let b = this.get('b'); | ||
return !this.get('anchorIsB') ? b : b + this.get('anchorAdjustment'); | ||
}, | ||
set(key, value) { | ||
this.set('b', !this.get('anchorIsB') ? value : value - this.get('anchorAdjustment')); | ||
return value; | ||
} | ||
}), | ||
|
||
first: Ember.computed('a', 'b', { | ||
get() { | ||
return Math.min(this.get('a'), this.get('b')); | ||
}, | ||
set(key, value) { | ||
if (this.get('a') <= this.get('b')) { | ||
this.set('a', value); | ||
} else { | ||
this.set('b', value); | ||
} | ||
return value; | ||
} | ||
}), | ||
|
||
last: Ember.computed('a', 'b', { | ||
get() { | ||
return Math.max(this.get('a'), this.get('b')); | ||
}, | ||
set(key, value) { | ||
if (this.get('a') > this.get('b')) { | ||
this.set('a', value); | ||
} else { | ||
this.set('b', value); | ||
} | ||
return value; | ||
} | ||
}), | ||
|
||
realFirst: Ember.computed('realA', 'realB', { | ||
get() { | ||
return Math.min(this.get('realA'), this.get('realB')); | ||
}, | ||
set(key, value) { | ||
if (this.get('realA') <= this.get('realB')) { | ||
this.set('realA', value); | ||
} else { | ||
this.set('realB', value); | ||
} | ||
return value; | ||
} | ||
}), | ||
|
||
realLast: Ember.computed('realA', 'realB', { | ||
get() { | ||
return Math.max(this.get('realA'), this.get('realB')); | ||
}, | ||
set(key, value) { | ||
if (this.get('realA') > this.get('realB')) { | ||
this.set('realA', value); | ||
} else { | ||
this.set('realB', value); | ||
} | ||
return value; | ||
} | ||
}), | ||
|
||
normalize() { | ||
this.setProperties({ | ||
a: this.get('realA'), | ||
b: this.get('realB'), | ||
anchorAdjustment: 0 | ||
}); | ||
if (this.get('anchorIsB')) { | ||
let a = this.get('a'); | ||
let b = this.get('b'); | ||
this.setProperties({ | ||
a: b, | ||
b: a, | ||
anchorIsB: false | ||
}); | ||
} | ||
}, | ||
|
||
move(ltBody, pivot, direction) { | ||
let a = this.get('a'); | ||
let b = this.get('b'); | ||
let n = ltBody.get('table.rows.length'); | ||
let clip = (i) => Math.min(Math.max(0, i), n - 1); | ||
let i; | ||
if (a === b) { | ||
i = clip(b + direction); | ||
this.set('b', i); | ||
} else { | ||
if (pivot === -1) { | ||
pivot = a; | ||
} | ||
if (pivot === a) { | ||
i = clip(b + direction); | ||
this.set('b', i); | ||
} else if (pivot === b) { | ||
i = clip(a + direction); | ||
this.set('a', i); | ||
} else if (direction > 0) { | ||
i = clip(this.get('last') + direction); | ||
this.set('last', i); | ||
} else { | ||
i = clip(this.get('first') + direction); | ||
this.set('first', i); | ||
} | ||
} | ||
run.schedule('afterRender', null, () => ltBody.makeRowAtVisible(i)); | ||
}, | ||
|
||
applyDomModifications(ltBody) { | ||
ltBody.get('scrollableDecorations').pushObject({ | ||
component: 'lt-row-range', | ||
namedArgs: { range: this } | ||
}); | ||
}, | ||
|
||
revertDomModifications(ltBody) { | ||
let decorations = ltBody.get('scrollableDecorations'); | ||
decorations.removeObject(decorations.findBy('namedArgs.range', this)); | ||
}, | ||
|
||
_onHandleMove: on('move', function() { | ||
this.trigger('handleMove', ...arguments); | ||
}), | ||
|
||
_onHandleDrop: on('drop', function() { | ||
this.trigger('handleDrop', ...arguments); | ||
}) | ||
|
||
}); | ||
|
Oops, something went wrong.