Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
persona
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hexang 息壤平台
persona
Commits
7a4d91d2
Commit
7a4d91d2
authored
13 years ago
by
Shane Tomlinson
Browse files
Options
Downloads
Patches
Plain Diff
Moving the relativeDate from manage_account to helpers.
parent
07779120
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
resources/static/pages/manage_account.js
+2
-83
2 additions, 83 deletions
resources/static/pages/manage_account.js
resources/static/shared/helpers.js
+93
-3
93 additions, 3 deletions
resources/static/shared/helpers.js
with
95 additions
and
86 deletions
resources/static/pages/manage_account.js
+
2
−
83
View file @
7a4d91d2
...
@@ -42,94 +42,13 @@ BrowserID.manageAccount = (function() {
...
@@ -42,94 +42,13 @@ BrowserID.manageAccount = (function() {
errors
=
bid
.
Errors
,
errors
=
bid
.
Errors
,
dom
=
bid
.
DOM
,
dom
=
bid
.
DOM
,
storage
=
bid
.
Storage
,
storage
=
bid
.
Storage
,
helpers
=
bid
.
Helpers
,
pageHelpers
=
bid
.
PageHelpers
,
pageHelpers
=
bid
.
PageHelpers
,
cancelEvent
=
pageHelpers
.
cancelEvent
,
cancelEvent
=
pageHelpers
.
cancelEvent
,
confirmAction
=
confirm
,
confirmAction
=
confirm
,
doc
=
document
,
doc
=
document
,
tooltip
=
bid
.
Tooltip
;
tooltip
=
bid
.
Tooltip
;
function
relativeDate
(
date
)
{
var
diff
=
(((
new
Date
()).
getTime
()
-
date
.
getTime
())
/
1000
),
day_diff
=
Math
.
floor
(
diff
/
86400
),
dObj
=
{
"
friendly
"
:
date
.
toLocaleDateString
(),
"
additional
"
:
date
.
toLocaleTimeString
(),
"
utc
"
:
date
.
toUTCString
(),
"
locale
"
:
date
.
toLocaleString
()
};
/* some kind of error */
if
(
day_diff
<
0
)
{
dObj
.
friendly
=
"
in the future!?!
"
;
return
dObj
;
}
else
if
(
isNaN
(
day_diff
))
{
dObj
.
friendly
=
dObj
.
additional
=
"
unknown
"
;
return
dObj
;
}
if
(
day_diff
===
0
)
{
if
(
diff
<
60
)
{
dObj
.
friendly
=
"
just now
"
;
return
dObj
;
}
if
(
diff
<
120
+
30
)
{
/* 1 minute plus some fuzz */
dObj
.
friendly
=
"
a minute ago
"
;
return
dObj
;
}
if
(
diff
<
3600
)
{
dObj
.
friendly
=
Math
.
floor
(
diff
/
60
)
+
"
minutes ago
"
;
return
dObj
;
}
if
(
diff
<
(
60
*
60
)
*
2
)
{
dObj
.
friendly
=
"
1 hour ago
"
;
return
dObj
;
}
if
(
diff
<
24
*
60
*
60
)
{
dObj
.
friendly
=
Math
.
floor
(
diff
/
3600
)
+
"
hours ago
"
;
return
dObj
;
}
}
if
(
day_diff
===
1
)
{
dObj
.
friendly
=
"
yesterday
"
;
return
dObj
;
}
if
(
day_diff
<
7
)
{
dObj
.
friendly
=
day_diff
+
"
days ago
"
;
return
dObj
;
}
if
(
day_diff
<
8
)
{
dObj
.
friendly
=
"
last week
"
;
return
dObj
;
}
/* for this scope: we want day of week and the date
plus the month (if different) */
if
(
day_diff
<
31
)
{
dObj
.
friendly
=
Math
.
ceil
(
day_diff
/
7
)
+
"
weeks ago
"
;
return
dObj
;
}
/* for this scope: we want month + date */
if
(
day_diff
<
62
)
{
dObj
.
friendly
=
"
a month ago
"
;
return
dObj
;
}
if
(
day_diff
<
365
)
{
dObj
.
friendly
=
Math
.
ceil
(
day_diff
/
31
)
+
"
months ago
"
;
return
dObj
;
}
/* for this scope: we want month + year */
if
(
day_diff
>=
365
&&
day_diff
<
730
)
{
dObj
.
additional
=
date
.
toLocaleDateString
();
dObj
.
friendly
=
"
a year ago
"
;
return
dObj
;
}
if
(
day_diff
>=
365
)
{
dObj
.
additional
=
date
.
toLocaleDateString
();
dObj
.
friendly
=
Math
.
ceil
(
day_diff
/
365
)
+
"
years ago
"
;
return
dObj
;
}
return
dObj
;
}
function
syncAndDisplayEmails
(
oncomplete
)
{
function
syncAndDisplayEmails
(
oncomplete
)
{
user
.
syncEmails
(
function
()
{
user
.
syncEmails
(
function
()
{
displayStoredEmails
(
oncomplete
);
displayStoredEmails
(
oncomplete
);
...
@@ -189,7 +108,7 @@ BrowserID.manageAccount = (function() {
...
@@ -189,7 +108,7 @@ BrowserID.manageAccount = (function() {
var
template
=
$
(
"
#templateUser
"
).
html
();
var
template
=
$
(
"
#templateUser
"
).
html
();
_
(
emails
).
each
(
function
(
data
,
e
)
{
_
(
emails
).
each
(
function
(
data
,
e
)
{
var
date
=
relativeDate
(
new
Date
(
data
.
created
));
var
date
=
helpers
.
relativeDate
(
new
Date
(
data
.
created
));
var
identity
=
_
.
template
(
template
,
{
var
identity
=
_
.
template
(
template
,
{
email
:
e
,
email
:
e
,
...
...
This diff is collapsed.
Click to expand it.
resources/static/shared/helpers.js
+
93
−
3
View file @
7a4d91d2
...
@@ -34,7 +34,7 @@
...
@@ -34,7 +34,7 @@
*
*
* ***** END LICENSE BLOCK ***** */
* ***** END LICENSE BLOCK ***** */
(
function
()
{
(
function
()
{
"
use strict
"
"
use strict
"
;
var
bid
=
BrowserID
,
var
bid
=
BrowserID
,
dom
=
bid
.
DOM
,
dom
=
bid
.
DOM
,
...
@@ -48,7 +48,7 @@
...
@@ -48,7 +48,7 @@
for
(
var
key
in
source
)
{
for
(
var
key
in
source
)
{
target
[
key
]
=
source
[
key
];
target
[
key
]
=
source
[
key
];
}
}
}
;
}
function
getAndValidateEmail
(
target
)
{
function
getAndValidateEmail
(
target
)
{
var
email
=
(
dom
.
getInner
(
target
)
||
""
).
trim
();
var
email
=
(
dom
.
getInner
(
target
)
||
""
).
trim
();
...
@@ -81,6 +81,88 @@
...
@@ -81,6 +81,88 @@
return
url
;
return
url
;
}
}
function
relativeDate
(
date
)
{
var
diff
=
(((
new
Date
()).
getTime
()
-
date
.
getTime
())
/
1000
),
day_diff
=
Math
.
floor
(
diff
/
86400
),
dObj
=
{
"
friendly
"
:
date
.
toLocaleDateString
(),
"
additional
"
:
date
.
toLocaleTimeString
(),
"
utc
"
:
date
.
toUTCString
(),
"
locale
"
:
date
.
toLocaleString
()
};
/* some kind of error */
if
(
day_diff
<
0
)
{
dObj
.
friendly
=
"
in the future!?!
"
;
return
dObj
;
}
else
if
(
isNaN
(
day_diff
))
{
dObj
.
friendly
=
dObj
.
additional
=
"
unknown
"
;
return
dObj
;
}
if
(
day_diff
===
0
)
{
if
(
diff
<
60
)
{
dObj
.
friendly
=
"
just now
"
;
return
dObj
;
}
if
(
diff
<
120
+
30
)
{
/* 1 minute plus some fuzz */
dObj
.
friendly
=
"
a minute ago
"
;
return
dObj
;
}
if
(
diff
<
3600
)
{
dObj
.
friendly
=
Math
.
floor
(
diff
/
60
)
+
"
minutes ago
"
;
return
dObj
;
}
if
(
diff
<
(
60
*
60
)
*
2
)
{
dObj
.
friendly
=
"
1 hour ago
"
;
return
dObj
;
}
if
(
diff
<
24
*
60
*
60
)
{
dObj
.
friendly
=
Math
.
floor
(
diff
/
3600
)
+
"
hours ago
"
;
return
dObj
;
}
}
if
(
day_diff
===
1
)
{
dObj
.
friendly
=
"
yesterday
"
;
return
dObj
;
}
if
(
day_diff
<
7
)
{
dObj
.
friendly
=
day_diff
+
"
days ago
"
;
return
dObj
;
}
if
(
day_diff
<
8
)
{
dObj
.
friendly
=
"
last week
"
;
return
dObj
;
}
/* for this scope: we want day of week and the date
plus the month (if different) */
if
(
day_diff
<
31
)
{
dObj
.
friendly
=
Math
.
ceil
(
day_diff
/
7
)
+
"
weeks ago
"
;
return
dObj
;
}
/* for this scope: we want month + date */
if
(
day_diff
<
62
)
{
dObj
.
friendly
=
"
a month ago
"
;
return
dObj
;
}
if
(
day_diff
<
365
)
{
dObj
.
friendly
=
Math
.
ceil
(
day_diff
/
31
)
+
"
months ago
"
;
return
dObj
;
}
/* for this scope: we want month + year */
if
(
day_diff
>=
365
&&
day_diff
<
730
)
{
dObj
.
additional
=
date
.
toLocaleDateString
();
dObj
.
friendly
=
"
a year ago
"
;
return
dObj
;
}
if
(
day_diff
>=
365
)
{
dObj
.
additional
=
date
.
toLocaleDateString
();
dObj
.
friendly
=
Math
.
ceil
(
day_diff
/
365
)
+
"
years ago
"
;
return
dObj
;
}
return
dObj
;
}
extend
(
helpers
,
{
extend
(
helpers
,
{
/**
/**
...
@@ -116,7 +198,15 @@
...
@@ -116,7 +198,15 @@
* @param {object} [params] - object to convert to GET parameters.
* @param {object} [params] - object to convert to GET parameters.
* @returns {string}
* @returns {string}
*/
*/
toURL
:
toURL
toURL
:
toURL
,
/**
* Get the date relative to now.
* @method relativeDate
* @param {Date} date
* @returns {string} date relative to now.
*/
relativeDate
:
relativeDate
});
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment