Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
29d86bd4
Commit
29d86bd4
authored
Dec 16, 2016
by
Bryce Johnson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor class PrettyTime to util obj prettyTime.
parent
df6eb9b1
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
37 deletions
+36
-37
app/assets/javascripts/issuable/time_tracking/components/collapsed_state.js.es6
.../issuable/time_tracking/components/collapsed_state.js.es6
+1
-1
app/assets/javascripts/issuable/time_tracking/components/comparison_pane.js.es6
.../issuable/time_tracking/components/comparison_pane.js.es6
+5
-5
app/assets/javascripts/lib/utils/pretty_time.js.es6
app/assets/javascripts/lib/utils/pretty_time.js.es6
+12
-14
spec/javascripts/issuable_time_tracker_spec.js.es6
spec/javascripts/issuable_time_tracker_spec.js.es6
+7
-6
spec/javascripts/pretty_time_spec.js.es6
spec/javascripts/pretty_time_spec.js.es6
+11
-11
No files found.
app/assets/javascripts/issuable/time_tracking/components/collapsed_state.js.es6
View file @
29d86bd4
...
...
@@ -15,7 +15,7 @@
],
methods: {
abbreviateTime(timeStr) {
return gl.
P
rettyTime.abbreviateTime(timeStr);
return gl.
utils.p
rettyTime.abbreviateTime(timeStr);
},
},
template: `
...
...
app/assets/javascripts/issuable/time_tracking/components/comparison_pane.js.es6
View file @
29d86bd4
...
...
@@ -2,7 +2,7 @@
//= require lib/utils/pretty_time
(() => {
const
PrettyTime = gl.P
rettyTime;
const
prettyTime = gl.utils.p
rettyTime;
Vue.component('time-tracking-comparison-pane', {
name: 'time-tracking-comparison-pane',
...
...
@@ -15,10 +15,10 @@
computed: {
parsedRemaining() {
const diffSeconds = this.timeEstimate - this.timeSpent;
return
P
rettyTime.parseSeconds(diffSeconds);
return
p
rettyTime.parseSeconds(diffSeconds);
},
timeRemainingHumanReadable() {
return
P
rettyTime.stringifyTime(this.parsedRemaining);
return
p
rettyTime.stringifyTime(this.parsedRemaining);
},
timeRemainingTooltip() {
const prefix = this.timeRemainingMinutes < 0 ? 'Over by' : 'Time remaining:';
...
...
@@ -37,10 +37,10 @@
},
/* Parsed time values */
parsedEstimate() {
return
P
rettyTime.parseSeconds(this.timeEstimate);
return
p
rettyTime.parseSeconds(this.timeEstimate);
},
parsedSpent() {
return
P
rettyTime.parseSeconds(this.timeSpent);
return
p
rettyTime.parseSeconds(this.timeSpent);
},
},
template: `
...
...
app/assets/javascripts/lib/utils/pretty_time.js.es6
View file @
29d86bd4
...
...
@@ -4,13 +4,13 @@
* stringifyTime condensed or non-condensed, abbreviateTimelengths)
* */
c
lass PrettyTime {
c
onst utils = window.gl.utils = gl.utils || {};
const prettyTime = utils.prettyTime = {
/*
* Accepts seconds and returns a timeObject { weeks: #, days: #, hours: #, minutes: # }
* Seconds can be negative or positive, zero or non-zero.
*/
static
parseSeconds(seconds) {
parseSeconds(seconds) {
const DAYS_PER_WEEK = 5;
const HOURS_PER_DAY = 8;
const MINUTES_PER_HOUR = 60;
...
...
@@ -24,7 +24,7 @@
minutes: 1,
};
let unorderedMinutes =
P
rettyTime.secondsToMinutes(seconds);
let unorderedMinutes =
p
rettyTime.secondsToMinutes(seconds);
return _.mapObject(timePeriodConstraints, (minutesPerPeriod) => {
const periodCount = Math.floor(unorderedMinutes / minutesPerPeriod);
...
...
@@ -33,35 +33,33 @@
return periodCount;
});
}
}
,
/*
* Accepts a timeObject and returns a condensed string representation of it
* (e.g. '1w 2d 3h 1m' or '1h 30m'). Zero value units are not included.
*/
st
atic st
ringifyTime(timeObject) {
stringifyTime(timeObject) {
const reducedTime = _.reduce(timeObject, (memo, unitValue, unitName) => {
const isNonZero = !!unitValue;
return isNonZero ? `${memo} ${unitValue}${unitName.charAt(0)}` : memo;
}, '').trim();
return reducedTime.length ? reducedTime : '0m';
}
}
,
/*
* Accepts a time string of any size (e.g. '1w 2d 3h 5m' or '1w 2d') and returns
* the first non-zero unit/value pair.
*/
static
abbreviateTime(timeStr) {
abbreviateTime(timeStr) {
return timeStr.split(' ')
.filter(unitStr => unitStr.charAt(0) !== '0')[0];
}
}
,
s
tatic s
econdsToMinutes(seconds) {
secondsToMinutes(seconds) {
return Math.abs(seconds / 60);
}
}
gl.PrettyTime = PrettyTime;
},
};
})(window.gl || (window.gl = {}));
spec/javascripts/issuable_time_tracker_spec.js.es6
View file @
29d86bd4
...
...
@@ -59,7 +59,6 @@ function initTimeTrackingComponent(opts) {
it('should show the "Comparison" pane when timeEstimate and time_spent are truthy', function(done) {
Vue.nextTick(() => {
debugger;
const $comparisonPane = this.timeTracker.$el.querySelector('.time-tracking-comparison-pane');
expect(this.timeTracker.showComparisonState).toBe(true);
done();
...
...
@@ -67,11 +66,14 @@ function initTimeTrackingComponent(opts) {
});
describe('Remaining meter', function() {
it('should display the remaining meter with the correct width', function() {
it('should display the remaining meter with the correct width', function(done) {
Vue.nextTick(() => {
const meterWidth = this.timeTracker.$el.querySelector('.time-tracking-comparison-pane .meter-fill').style.width;
const correctWidth = '5%';
expect(meterWidth).toBe(correctWidth);
done();
})
});
it('should display the remaining meter with the correct background color when within estimate', function(done) {
...
...
@@ -102,7 +104,6 @@ function initTimeTrackingComponent(opts) {
it('should display the human readable version of time estimated', function(done) {
Vue.nextTick(() => {
const estimateText = this.timeTracker.$el.querySelector('.time-tracking-estimate-only-pane').innerText;
debugger;
const correctText = 'Estimated: 2h 46m';
expect(estimateText).toBe(correctText);
...
...
spec/javascripts/pretty_time_spec.js.es6
View file @
29d86bd4
//= require lib/utils/pretty_time
(() => {
const
PrettyTime = gl.P
rettyTime;
const
prettyTime = gl.utils.p
rettyTime;
describe('
P
rettyTime methods', function () {
describe('
p
rettyTime methods', function () {
describe('parseSeconds', function () {
it('should correctly parse a negative value', function () {
const parser =
P
rettyTime.parseSeconds;
const parser =
p
rettyTime.parseSeconds;
const zeroSeconds = parser(-1000);
...
...
@@ -17,7 +17,7 @@
});
it('should correctly parse a zero value', function () {
const parser =
P
rettyTime.parseSeconds;
const parser =
p
rettyTime.parseSeconds;
const zeroSeconds = parser(0);
...
...
@@ -28,7 +28,7 @@
});
it('should correctly parse a small non-zero second values', function () {
const parser =
P
rettyTime.parseSeconds;
const parser =
p
rettyTime.parseSeconds;
const subOneMinute = parser(10);
...
...
@@ -53,7 +53,7 @@
});
it('should correctly parse large second values', function () {
const parser =
P
rettyTime.parseSeconds;
const parser =
p
rettyTime.parseSeconds;
const aboveOneHour = parser(4800);
...
...
@@ -87,7 +87,7 @@
minutes: 20,
};
const timeString =
P
rettyTime.stringifyTime(timeObject);
const timeString =
p
rettyTime.stringifyTime(timeObject);
expect(timeString).toBe('1w 4d 7h 20m');
});
...
...
@@ -100,7 +100,7 @@
minutes: 20,
};
const timeString =
P
rettyTime.stringifyTime(timeObject);
const timeString =
p
rettyTime.stringifyTime(timeObject);
expect(timeString).toBe('4d 20m');
});
...
...
@@ -113,7 +113,7 @@
minutes: 0,
};
const timeString =
P
rettyTime.stringifyTime(timeObject);
const timeString =
p
rettyTime.stringifyTime(timeObject);
expect(timeString).toBe('0m');
});
...
...
@@ -122,12 +122,12 @@
describe('abbreviateTime', function () {
it('should abbreviate stringified times for weeks', function () {
const fullTimeString = '1w 3d 4h 5m';
expect(
P
rettyTime.abbreviateTime(fullTimeString)).toBe('1w');
expect(
p
rettyTime.abbreviateTime(fullTimeString)).toBe('1w');
});
it('should abbreviate stringified times for non-weeks', function () {
const fullTimeString = '0w 3d 4h 5m';
expect(
P
rettyTime.abbreviateTime(fullTimeString)).toBe('3d');
expect(
p
rettyTime.abbreviateTime(fullTimeString)).toBe('3d');
});
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment