Mercurial > bugzilla-dashboard
annotate js/modules/app.js @ 71:4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
author | Atul Varma <avarma@mozilla.com> |
---|---|
date | Sun, 25 Apr 2010 17:55:54 -0700 |
parents | 6f5b5b404066 |
children | 0eab9a3ff12f |
rev | line source |
---|---|
41 | 1 Require.modules["app/login"] = function(exports) { |
2 var callbacks = []; | |
3 var username; | |
4 var password; | |
59
440c8e2d776d
dashboard now auto-authenticated via cached form field password on firefox, if available.
Atul Varma <avarma@mozilla.com>
parents:
58
diff
changeset
|
5 var passwordProvider; |
440c8e2d776d
dashboard now auto-authenticated via cached form field password on firefox, if available.
Atul Varma <avarma@mozilla.com>
parents:
58
diff
changeset
|
6 |
440c8e2d776d
dashboard now auto-authenticated via cached form field password on firefox, if available.
Atul Varma <avarma@mozilla.com>
parents:
58
diff
changeset
|
7 exports.setPasswordProvider = function setPasswordProvider(pp) { |
440c8e2d776d
dashboard now auto-authenticated via cached form field password on firefox, if available.
Atul Varma <avarma@mozilla.com>
parents:
58
diff
changeset
|
8 passwordProvider = pp; |
440c8e2d776d
dashboard now auto-authenticated via cached form field password on firefox, if available.
Atul Varma <avarma@mozilla.com>
parents:
58
diff
changeset
|
9 }; |
41 | 10 |
11 exports.whenChanged = function whenChanged(cb) { | |
12 callbacks.push(cb); | |
13 }; | |
14 | |
53
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
15 exports.get = function get() { |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
16 var isLoggedIn = (username && username != ""); |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
17 var isAuthenticated = (isLoggedIn && password && password != ""); |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
18 |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
19 return { |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
20 username: username, |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
21 password: password, |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
22 isLoggedIn: isLoggedIn, |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
23 isAuthenticated: isAuthenticated |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
24 }; |
41 | 25 }; |
26 | |
27 exports.set = function set(newUsername, newPassword) { | |
59
440c8e2d776d
dashboard now auto-authenticated via cached form field password on firefox, if available.
Atul Varma <avarma@mozilla.com>
parents:
58
diff
changeset
|
28 if ((newUsername && newUsername != "") && |
440c8e2d776d
dashboard now auto-authenticated via cached form field password on firefox, if available.
Atul Varma <avarma@mozilla.com>
parents:
58
diff
changeset
|
29 (!newPassword || newPassword == "") && |
440c8e2d776d
dashboard now auto-authenticated via cached form field password on firefox, if available.
Atul Varma <avarma@mozilla.com>
parents:
58
diff
changeset
|
30 (passwordProvider)) |
440c8e2d776d
dashboard now auto-authenticated via cached form field password on firefox, if available.
Atul Varma <avarma@mozilla.com>
parents:
58
diff
changeset
|
31 newPassword = passwordProvider(newUsername); |
440c8e2d776d
dashboard now auto-authenticated via cached form field password on firefox, if available.
Atul Varma <avarma@mozilla.com>
parents:
58
diff
changeset
|
32 |
41 | 33 if (newUsername == username && newPassword == password) |
34 return; | |
35 | |
36 username = newUsername; | |
37 password = newPassword; | |
38 | |
53
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
39 var info = exports.get(); |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
40 |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
41 callbacks.forEach(function(cb) { cb(info); }); |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
42 }; |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
43 }; |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
44 |
71
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
45 Require.modules["app/bugzilla-serial"] = function(exports, require) { |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
46 const EVENTS = ["abort", "error", "load"]; |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
47 |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
48 var myproto = require("bugzilla"); |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
49 var active = null; |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
50 var queue = []; |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
51 |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
52 function enqueue(bugzilla, options) { |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
53 queue.push({bugzilla: bugzilla, options: options}); |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
54 if (!active) |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
55 activateNextInQueue(); |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
56 } |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
57 |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
58 function activateNextInQueue() { |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
59 if (queue.length) { |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
60 var entry = queue.splice(0, 1)[0]; |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
61 var xhr = myproto.ajax.call(entry.bugzilla, entry.options); |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
62 EVENTS.forEach(function(name) { |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
63 xhr.addEventListener(name, onDone, false); |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
64 }); |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
65 active = xhr; |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
66 } else |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
67 active = null; |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
68 } |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
69 |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
70 function onDone(event) { |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
71 var xhr = event.target; |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
72 EVENTS.forEach(function(name) { |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
73 xhr.removeEventListener(name, onDone, false); |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
74 }); |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
75 activateNextInQueue(); |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
76 }; |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
77 |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
78 exports.Bugzilla = { |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
79 ajax: function ajax(options) { |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
80 enqueue(this, options); |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
81 }, |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
82 __proto__: myproto |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
83 }; |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
84 }; |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
85 |
58
f9001601bed6
authenticated users now get an authenticated dashboard w/ confidential bugs.
Atul Varma <avarma@mozilla.com>
parents:
56
diff
changeset
|
86 Require.modules["app/bugzilla-auth"] = function(exports, require) { |
71
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
87 var myproto = require("app/bugzilla-serial").Bugzilla; |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
88 |
58
f9001601bed6
authenticated users now get an authenticated dashboard w/ confidential bugs.
Atul Varma <avarma@mozilla.com>
parents:
56
diff
changeset
|
89 exports.Bugzilla = { |
f9001601bed6
authenticated users now get an authenticated dashboard w/ confidential bugs.
Atul Varma <avarma@mozilla.com>
parents:
56
diff
changeset
|
90 ajax: function ajax(options) { |
f9001601bed6
authenticated users now get an authenticated dashboard w/ confidential bugs.
Atul Varma <avarma@mozilla.com>
parents:
56
diff
changeset
|
91 var user = require("app/login").get(); |
f9001601bed6
authenticated users now get an authenticated dashboard w/ confidential bugs.
Atul Varma <avarma@mozilla.com>
parents:
56
diff
changeset
|
92 |
f9001601bed6
authenticated users now get an authenticated dashboard w/ confidential bugs.
Atul Varma <avarma@mozilla.com>
parents:
56
diff
changeset
|
93 if (user.isAuthenticated) { |
f9001601bed6
authenticated users now get an authenticated dashboard w/ confidential bugs.
Atul Varma <avarma@mozilla.com>
parents:
56
diff
changeset
|
94 if (!options.data) |
f9001601bed6
authenticated users now get an authenticated dashboard w/ confidential bugs.
Atul Varma <avarma@mozilla.com>
parents:
56
diff
changeset
|
95 options.data = {}; |
f9001601bed6
authenticated users now get an authenticated dashboard w/ confidential bugs.
Atul Varma <avarma@mozilla.com>
parents:
56
diff
changeset
|
96 options.data.username = user.username; |
f9001601bed6
authenticated users now get an authenticated dashboard w/ confidential bugs.
Atul Varma <avarma@mozilla.com>
parents:
56
diff
changeset
|
97 options.data.password = user.password; |
f9001601bed6
authenticated users now get an authenticated dashboard w/ confidential bugs.
Atul Varma <avarma@mozilla.com>
parents:
56
diff
changeset
|
98 } |
f9001601bed6
authenticated users now get an authenticated dashboard w/ confidential bugs.
Atul Varma <avarma@mozilla.com>
parents:
56
diff
changeset
|
99 |
71
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
100 return myproto.ajax.call(this, options); |
58
f9001601bed6
authenticated users now get an authenticated dashboard w/ confidential bugs.
Atul Varma <avarma@mozilla.com>
parents:
56
diff
changeset
|
101 }, |
71
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
102 __proto__: myproto |
58
f9001601bed6
authenticated users now get an authenticated dashboard w/ confidential bugs.
Atul Varma <avarma@mozilla.com>
parents:
56
diff
changeset
|
103 }; |
f9001601bed6
authenticated users now get an authenticated dashboard w/ confidential bugs.
Atul Varma <avarma@mozilla.com>
parents:
56
diff
changeset
|
104 }; |
f9001601bed6
authenticated users now get an authenticated dashboard w/ confidential bugs.
Atul Varma <avarma@mozilla.com>
parents:
56
diff
changeset
|
105 |
68 | 106 Require.modules["app/commands"] = function(exports, require) { |
107 var commands = {}; | |
108 | |
109 exports.get = function get(name) { | |
110 if (!(name in commands)) | |
111 throw new Error("command not found: " + name); | |
112 return commands[name]; | |
113 }; | |
114 | |
115 exports.register = function(options) { | |
116 if (options.name in commands) | |
117 throw new Error("command already registered: " + options.name); | |
118 commands[options.name] = options; | |
119 }; | |
120 }; | |
121 | |
53
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
122 Require.modules["app/ui/login-form"] = function(exports, require) { |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
123 var $ = require("jQuery"); |
59
440c8e2d776d
dashboard now auto-authenticated via cached form field password on firefox, if available.
Atul Varma <avarma@mozilla.com>
parents:
58
diff
changeset
|
124 var cachedUsername = $("#login .username").val(); |
440c8e2d776d
dashboard now auto-authenticated via cached form field password on firefox, if available.
Atul Varma <avarma@mozilla.com>
parents:
58
diff
changeset
|
125 var cachedPassword = $("#login .password").val(); |
41 | 126 |
53
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
127 $("#login form").submit( |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
128 function(event) { |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
129 event.preventDefault(); |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
130 require("app/login").set($("#login .username").val(), |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
131 $("#login .password").val()); |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
132 $("#login").fadeOut(); |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
133 }); |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
134 |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
135 require("app/login").whenChanged( |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
136 function maybeChangeUsernameField(user) { |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
137 var usernameField = $("#login .username"); |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
138 if (user.isLoggedIn && usernameField.val() != user.username) |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
139 usernameField.val(user.username); |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
140 }); |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
141 |
59
440c8e2d776d
dashboard now auto-authenticated via cached form field password on firefox, if available.
Atul Varma <avarma@mozilla.com>
parents:
58
diff
changeset
|
142 require("app/login").setPasswordProvider( |
440c8e2d776d
dashboard now auto-authenticated via cached form field password on firefox, if available.
Atul Varma <avarma@mozilla.com>
parents:
58
diff
changeset
|
143 function maybeGetCachedPasswordFromForm(username) { |
440c8e2d776d
dashboard now auto-authenticated via cached form field password on firefox, if available.
Atul Varma <avarma@mozilla.com>
parents:
58
diff
changeset
|
144 if (cachedUsername == username) |
440c8e2d776d
dashboard now auto-authenticated via cached form field password on firefox, if available.
Atul Varma <avarma@mozilla.com>
parents:
58
diff
changeset
|
145 return cachedPassword; |
440c8e2d776d
dashboard now auto-authenticated via cached form field password on firefox, if available.
Atul Varma <avarma@mozilla.com>
parents:
58
diff
changeset
|
146 return ""; |
440c8e2d776d
dashboard now auto-authenticated via cached form field password on firefox, if available.
Atul Varma <avarma@mozilla.com>
parents:
58
diff
changeset
|
147 }); |
440c8e2d776d
dashboard now auto-authenticated via cached form field password on firefox, if available.
Atul Varma <avarma@mozilla.com>
parents:
58
diff
changeset
|
148 |
53
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
149 exports.init = function init() { |
41 | 150 }; |
151 }; | |
43
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
152 |
63 | 153 Require.modules["app/ui/file-bug"] = function(exports, require) { |
154 const EM_DASH = "\u2014"; | |
155 | |
156 var $ = require("jQuery"); | |
157 var cache = require("cache"); | |
158 var bugzilla = require("app/bugzilla-auth").Bugzilla; | |
159 var window = require("window"); | |
160 var config = cache.get("configuration"); | |
161 var needToFetchConfig = config ? false : true; | |
162 var categories; | |
163 var queuedRespond; | |
164 | |
165 function buildCategories() { | |
166 categories = []; | |
167 for (product in config.product) | |
168 for (component in config.product[product].component) | |
169 categories.push(product + EM_DASH + component); | |
170 } | |
171 | |
172 function fetchConfig() { | |
173 bugzilla.ajax({url: "/configuration", | |
174 data: {flags: 0}, | |
175 success: function(result) { | |
176 config = result; | |
177 cache.set("configuration", result); | |
178 if (queuedRespond) | |
179 queuedRespond(); | |
180 }}); | |
181 } | |
182 | |
183 var categoryOptions = { | |
184 minLength: 2, | |
185 source: function(request, response) { | |
186 function respond() { | |
187 queuedRespond = null; | |
188 | |
189 var suggs = []; | |
190 var terms = request.term.split(" "); | |
191 | |
192 if (!categories) | |
193 buildCategories(); | |
194 | |
195 categories.forEach( | |
196 function(category) { | |
197 for (var i = 0; i < terms.length; i++) | |
198 if (!category.match(terms[i], "i")) | |
199 return; | |
200 suggs.push(category); | |
201 }); | |
202 | |
203 response(suggs); | |
204 }; | |
205 | |
206 if (!config) { | |
207 queuedRespond = respond; | |
208 if (needToFetchConfig) { | |
209 needToFetchConfig = false; | |
210 fetchConfig(); | |
211 } | |
212 } else | |
213 respond(); | |
214 } | |
215 }; | |
216 | |
217 $("input#category").autocomplete(categoryOptions); | |
218 $("#file-bug").submit( | |
219 function(event) { | |
220 event.preventDefault(); | |
221 var parts = $("input#category").val().split(EM_DASH); | |
222 window.open(bugzilla.BASE_UI_URL + "/enter_bug.cgi?" + | |
223 "product=" + escape(parts[0]) + "&" + | |
224 "component=" + escape(parts[1])); | |
225 }); | |
226 | |
227 exports.init = function init() { | |
228 }; | |
229 }; | |
230 | |
60
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
231 Require.modules["app/ui/find-user"] = function(exports, require) { |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
232 var $ = require("jQuery"); |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
233 var bugzilla = require("app/bugzilla-auth").Bugzilla; |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
234 var window = require("window"); |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
235 var currReq; |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
236 |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
237 var options = { |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
238 minLength: 2, |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
239 delay: 1000, |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
240 source: function(request, response) { |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
241 function success(result) { |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
242 currReq = null; |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
243 var suggs = []; |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
244 result.users.forEach( |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
245 function(user) { |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
246 suggs.push({label: user.real_name + " (" + user.name + ")", |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
247 value: user.name}); |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
248 }); |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
249 response(suggs); |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
250 } |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
251 if (currReq) |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
252 currReq.abort(); |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
253 currReq = bugzilla.ajax({url: "/user", |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
254 data: {match: request.term}, |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
255 success: success}); |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
256 } |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
257 }; |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
258 |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
259 $("#find-user .query").autocomplete(options); |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
260 $("#find-user form").submit( |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
261 function(event) { |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
262 event.preventDefault(); |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
263 var username = $("#find-user .query").val(); |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
264 var url = require("app/ui/hash").usernameToHash(username); |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
265 window.open(url); |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
266 }); |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
267 |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
268 exports.init = function init() { |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
269 }; |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
270 }; |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
271 |
43
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
272 Require.modules["app/ui"] = function(exports, require) { |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
273 var $ = require("jQuery"); |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
274 |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
275 require("app/login").whenChanged( |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
276 function changeUI(user) { |
54
1199b970c68b
present 'Log In' when user isn't authenticated
Atul Varma <avarma@mozilla.com>
parents:
53
diff
changeset
|
277 var show = { |
1199b970c68b
present 'Log In' when user isn't authenticated
Atul Varma <avarma@mozilla.com>
parents:
53
diff
changeset
|
278 "no-login": false, |
1199b970c68b
present 'Log In' when user isn't authenticated
Atul Varma <avarma@mozilla.com>
parents:
53
diff
changeset
|
279 "login": false, |
1199b970c68b
present 'Log In' when user isn't authenticated
Atul Varma <avarma@mozilla.com>
parents:
53
diff
changeset
|
280 "auth-login": false, |
56
4728c2db6fd6
changed 'Log In' to 'Authenticate' if user is logged in but unauthenticated.
Atul Varma <avarma@mozilla.com>
parents:
55
diff
changeset
|
281 "no-auth": false, |
4728c2db6fd6
changed 'Log In' to 'Authenticate' if user is logged in but unauthenticated.
Atul Varma <avarma@mozilla.com>
parents:
55
diff
changeset
|
282 "no-auth-login": false |
54
1199b970c68b
present 'Log In' when user isn't authenticated
Atul Varma <avarma@mozilla.com>
parents:
53
diff
changeset
|
283 }; |
1199b970c68b
present 'Log In' when user isn't authenticated
Atul Varma <avarma@mozilla.com>
parents:
53
diff
changeset
|
284 |
43
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
285 if (user.isLoggedIn) { |
54
1199b970c68b
present 'Log In' when user isn't authenticated
Atul Varma <avarma@mozilla.com>
parents:
53
diff
changeset
|
286 show["login"] = true; |
1199b970c68b
present 'Log In' when user isn't authenticated
Atul Varma <avarma@mozilla.com>
parents:
53
diff
changeset
|
287 if (user.isAuthenticated) |
1199b970c68b
present 'Log In' when user isn't authenticated
Atul Varma <avarma@mozilla.com>
parents:
53
diff
changeset
|
288 show["auth-login"] = true; |
56
4728c2db6fd6
changed 'Log In' to 'Authenticate' if user is logged in but unauthenticated.
Atul Varma <avarma@mozilla.com>
parents:
55
diff
changeset
|
289 else { |
54
1199b970c68b
present 'Log In' when user isn't authenticated
Atul Varma <avarma@mozilla.com>
parents:
53
diff
changeset
|
290 show["no-auth"] = true; |
56
4728c2db6fd6
changed 'Log In' to 'Authenticate' if user is logged in but unauthenticated.
Atul Varma <avarma@mozilla.com>
parents:
55
diff
changeset
|
291 show["no-auth-login"] = true; |
4728c2db6fd6
changed 'Log In' to 'Authenticate' if user is logged in but unauthenticated.
Atul Varma <avarma@mozilla.com>
parents:
55
diff
changeset
|
292 } |
43
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
293 } else { |
54
1199b970c68b
present 'Log In' when user isn't authenticated
Atul Varma <avarma@mozilla.com>
parents:
53
diff
changeset
|
294 show["no-login"] = true; |
1199b970c68b
present 'Log In' when user isn't authenticated
Atul Varma <avarma@mozilla.com>
parents:
53
diff
changeset
|
295 show["no-auth"] = true; |
1199b970c68b
present 'Log In' when user isn't authenticated
Atul Varma <avarma@mozilla.com>
parents:
53
diff
changeset
|
296 } |
1199b970c68b
present 'Log In' when user isn't authenticated
Atul Varma <avarma@mozilla.com>
parents:
53
diff
changeset
|
297 |
1199b970c68b
present 'Log In' when user isn't authenticated
Atul Varma <avarma@mozilla.com>
parents:
53
diff
changeset
|
298 for (classSuffix in show) { |
1199b970c68b
present 'Log In' when user isn't authenticated
Atul Varma <avarma@mozilla.com>
parents:
53
diff
changeset
|
299 var query = $(".requires-" + classSuffix); |
1199b970c68b
present 'Log In' when user isn't authenticated
Atul Varma <avarma@mozilla.com>
parents:
53
diff
changeset
|
300 if (show[classSuffix]) |
1199b970c68b
present 'Log In' when user isn't authenticated
Atul Varma <avarma@mozilla.com>
parents:
53
diff
changeset
|
301 query.show(); |
1199b970c68b
present 'Log In' when user isn't authenticated
Atul Varma <avarma@mozilla.com>
parents:
53
diff
changeset
|
302 else |
1199b970c68b
present 'Log In' when user isn't authenticated
Atul Varma <avarma@mozilla.com>
parents:
53
diff
changeset
|
303 query.hide(); |
43
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
304 } |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
305 }); |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
306 |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
307 $("#header .menu li").click( |
68 | 308 function onMenuItemClick(event) { |
309 if (this.hasAttribute("data-command")) { | |
310 var cmdName = this.getAttribute("data-command"); | |
311 require("app/commands").get(cmdName).execute(); | |
312 } else | |
313 openDialog(this.getAttribute("data-dialog")); | |
43
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
314 }); |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
315 |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
316 $(".dialog").click( |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
317 function dismissDialogOnOutsideClick(event) { |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
318 if (event.target == this) |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
319 $(this).fadeOut(); |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
320 }); |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
321 |
64
a196cc29fffb
ESC in dialog now makes it go away
Atul Varma <avarma@mozilla.com>
parents:
63
diff
changeset
|
322 function dismissDialogOnEscape(event) { |
a196cc29fffb
ESC in dialog now makes it go away
Atul Varma <avarma@mozilla.com>
parents:
63
diff
changeset
|
323 if (event.keyCode == 27) |
a196cc29fffb
ESC in dialog now makes it go away
Atul Varma <avarma@mozilla.com>
parents:
63
diff
changeset
|
324 $(this).fadeOut(); |
a196cc29fffb
ESC in dialog now makes it go away
Atul Varma <avarma@mozilla.com>
parents:
63
diff
changeset
|
325 } |
a196cc29fffb
ESC in dialog now makes it go away
Atul Varma <avarma@mozilla.com>
parents:
63
diff
changeset
|
326 |
a196cc29fffb
ESC in dialog now makes it go away
Atul Varma <avarma@mozilla.com>
parents:
63
diff
changeset
|
327 // For Safari. |
a196cc29fffb
ESC in dialog now makes it go away
Atul Varma <avarma@mozilla.com>
parents:
63
diff
changeset
|
328 $(".dialog").keyup(dismissDialogOnEscape); |
a196cc29fffb
ESC in dialog now makes it go away
Atul Varma <avarma@mozilla.com>
parents:
63
diff
changeset
|
329 // For Firefox. |
a196cc29fffb
ESC in dialog now makes it go away
Atul Varma <avarma@mozilla.com>
parents:
63
diff
changeset
|
330 $(".dialog").keypress(dismissDialogOnEscape); |
a196cc29fffb
ESC in dialog now makes it go away
Atul Varma <avarma@mozilla.com>
parents:
63
diff
changeset
|
331 |
43
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
332 function setupDocumentTitleChanger(document) { |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
333 const BASE_TITLE = document.title; |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
334 |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
335 require("app/login").whenChanged( |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
336 function changeTitle(user) { |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
337 var title = BASE_TITLE; |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
338 |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
339 if (user.isLoggedIn) |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
340 title = user.username + "'s " + BASE_TITLE; |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
341 |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
342 if (document.title != title) { |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
343 document.title = title; |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
344 $("#header .title").text(title); |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
345 } |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
346 }); |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
347 }; |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
348 |
65
8294f3d1efee
Startup dialog gains focus on open
Atul Varma <avarma@mozilla.com>
parents:
64
diff
changeset
|
349 function openDialog(name) { |
8294f3d1efee
Startup dialog gains focus on open
Atul Varma <avarma@mozilla.com>
parents:
64
diff
changeset
|
350 var dialog = $("#" + name); |
8294f3d1efee
Startup dialog gains focus on open
Atul Varma <avarma@mozilla.com>
parents:
64
diff
changeset
|
351 if (dialog.length == 0) |
8294f3d1efee
Startup dialog gains focus on open
Atul Varma <avarma@mozilla.com>
parents:
64
diff
changeset
|
352 throw new Error("dialog not found: " + name); |
8294f3d1efee
Startup dialog gains focus on open
Atul Varma <avarma@mozilla.com>
parents:
64
diff
changeset
|
353 dialog.fadeIn( |
8294f3d1efee
Startup dialog gains focus on open
Atul Varma <avarma@mozilla.com>
parents:
64
diff
changeset
|
354 function() { |
8294f3d1efee
Startup dialog gains focus on open
Atul Varma <avarma@mozilla.com>
parents:
64
diff
changeset
|
355 dialog.find("input:first").focus(); |
8294f3d1efee
Startup dialog gains focus on open
Atul Varma <avarma@mozilla.com>
parents:
64
diff
changeset
|
356 }); |
53
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
357 }; |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
358 |
43
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
359 exports.init = function init(document) { |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
360 setupDocumentTitleChanger(document); |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
361 |
53
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
362 require("app/ui/dashboard").init(); |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
363 require("app/ui/login-form").init(); |
60
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
364 require("app/ui/find-user").init(); |
63 | 365 require("app/ui/file-bug").init(); |
53
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
366 require("app/ui/hash").init(document); |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
367 |
65
8294f3d1efee
Startup dialog gains focus on open
Atul Varma <avarma@mozilla.com>
parents:
64
diff
changeset
|
368 if (!require("app/login").get().isLoggedIn) |
8294f3d1efee
Startup dialog gains focus on open
Atul Varma <avarma@mozilla.com>
parents:
64
diff
changeset
|
369 openDialog("login"); |
53
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
370 }; |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
371 }; |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
372 |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
373 Require.modules["app/ui/hash"] = function(exports, require) { |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
374 function usernameFromHash(location) { |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
375 if (location.hash) { |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
376 var match = location.hash.match(/#username=(.*)/); |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
377 if (match) |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
378 return unescape(match[1]); |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
379 } |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
380 return ""; |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
381 } |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
382 |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
383 function setLoginFromHash(location) { |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
384 var username = usernameFromHash(location); |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
385 |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
386 var user = require("app/login").get(); |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
387 if (user.username != username) |
59
440c8e2d776d
dashboard now auto-authenticated via cached form field password on firefox, if available.
Atul Varma <avarma@mozilla.com>
parents:
58
diff
changeset
|
388 require("app/login").set(username); |
53
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
389 } |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
390 |
60
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
391 exports.usernameToHash = function usernameToHash(username) { |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
392 return "#username=" + escape(username); |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
393 }; |
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
394 |
53
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
395 exports.init = function init(document) { |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
396 require("app/login").whenChanged( |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
397 function(user) { |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
398 if (user.isLoggedIn) { |
60
07d3d1560b93
added find a user functionality
Atul Varma <avarma@mozilla.com>
parents:
59
diff
changeset
|
399 var hash = exports.usernameToHash(user.username); |
53
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
400 if (document.location.hash != hash) |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
401 document.location.hash = hash; |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
402 } else |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
403 document.location.hash = ""; |
43
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
404 }); |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
405 |
53
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
406 var window = document.defaultView; |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
407 |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
408 function onHashChange() { |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
409 setLoginFromHash(document.location); |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
410 } |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
411 |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
412 if ("onhashchange" in window) |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
413 window.addEventListener("hashchange", onHashChange, false); |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
414 else |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
415 window.setInterval(onHashChange, 1000); |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
416 |
aa9b33b10820
dashboard responds to location.hash changes now.
Atul Varma <avarma@mozilla.com>
parents:
51
diff
changeset
|
417 onHashChange(); |
43
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
418 }; |
0974c1df3714
moved lots of app ui logic to require('app/ui')
Atul Varma <avarma@mozilla.com>
parents:
41
diff
changeset
|
419 }; |
47
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
420 |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
421 Require.modules["app/ui/dashboard"] = function(exports, require) { |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
422 var $ = require("jQuery"); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
423 var cache = require("cache"); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
424 var dateUtils = require("date-utils"); |
58
f9001601bed6
authenticated users now get an authenticated dashboard w/ confidential bugs.
Atul Varma <avarma@mozilla.com>
parents:
56
diff
changeset
|
425 var bugzilla = require("app/bugzilla-auth").Bugzilla; |
47
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
426 var window = require("window"); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
427 |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
428 function sortByLastChanged(bugs) { |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
429 var lctimes = {}; |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
430 |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
431 bugs.forEach( |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
432 function(bug) { |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
433 lctimes[bug.id] = dateUtils.dateFromISO8601(bug.last_change_time); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
434 }); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
435 |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
436 function compare(a, b) { |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
437 var alc = lctimes[a.id]; |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
438 var blc = lctimes[b.id]; |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
439 |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
440 if (alc < blc) |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
441 return -1; |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
442 if (alc > blc) |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
443 return 1; |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
444 return 0; |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
445 } |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
446 |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
447 bugs.sort(compare); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
448 } |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
449 |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
450 function updatePrettyDates(query) { |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
451 query.find(".last-changed").each( |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
452 function() { |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
453 var lcTime = $(this).attr("data-last-change"); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
454 $(this).text(dateUtils.prettyDate(lcTime)); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
455 }); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
456 } |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
457 |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
458 const PRETTY_DATE_UPDATE_INTERVAL = 1000 * 60; |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
459 |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
460 window.setInterval(function() { updatePrettyDates($("#reports")); }, |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
461 PRETTY_DATE_UPDATE_INTERVAL); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
462 |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
463 function showBugs(query, bugs) { |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
464 var table = $("#templates .bugs").clone(); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
465 var rowTemplate = table.find(".bug-row").remove(); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
466 sortByLastChanged(bugs); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
467 bugs.reverse(); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
468 bugs.forEach( |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
469 function(bug) { |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
470 var row = rowTemplate.clone(); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
471 row.attr("id", "bug-id-" + bug.id); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
472 row.find(".summary").text(bug.summary); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
473 row.addClass("status-" + bug.status); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
474 if (bug.priority != "--") { |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
475 row.addClass(bug.priority); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
476 row.addClass(bug.severity); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
477 } |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
478 row.find(".last-changed").attr("data-last-change", |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
479 bug.last_change_time); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
480 |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
481 row.click( |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
482 function onClick() { |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
483 window.open(bugzilla.getShowBugURL(bug.id)); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
484 }); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
485 |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
486 row.hover( |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
487 function onIn() { |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
488 var tooltip = $("#templates .bug-tooltip").clone(); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
489 tooltip.find(".priority").text(bug.priority); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
490 // TODO: Show more information in tooltip. |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
491 $(this).append(tooltip); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
492 }, |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
493 function onOut() { |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
494 $(this).find(".bug-tooltip").remove(); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
495 }); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
496 |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
497 table.append(row); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
498 }); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
499 updatePrettyDates(table); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
500 query.find(".bugs").remove(); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
501 query.append(table); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
502 table.hide(); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
503 removeDuplicateBugs(); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
504 table.fadeIn(); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
505 } |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
506 |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
507 // Remove duplicate bugs, preferring the first listing of a bug in |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
508 // the DOM to later ones. This is b/c the reports further down the |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
509 // page are the less "interesting" ones, and we want to capture |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
510 // the most "interesting" part of each bug. |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
511 function removeDuplicateBugs() { |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
512 var visited = {}; |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
513 $("#reports .bug-row").each( |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
514 function() { |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
515 var id = $(this).attr("id"); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
516 if (id in visited) |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
517 $(this).remove(); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
518 else |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
519 visited[id] = true; |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
520 }); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
521 } |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
522 |
67
d0f5f87e0b0a
dashboard stores per-user data in cache now.
Atul Varma <avarma@mozilla.com>
parents:
65
diff
changeset
|
523 function report(selector, key, searchTerms) { |
47
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
524 var newTerms = {__proto__: defaults}; |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
525 for (name in searchTerms) |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
526 newTerms[name.replace(/_DOT_/g, ".")] = searchTerms[name]; |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
527 |
67
d0f5f87e0b0a
dashboard stores per-user data in cache now.
Atul Varma <avarma@mozilla.com>
parents:
65
diff
changeset
|
528 var cacheKey = key + "/" + selector; |
d0f5f87e0b0a
dashboard stores per-user data in cache now.
Atul Varma <avarma@mozilla.com>
parents:
65
diff
changeset
|
529 var cached = cache.get(cacheKey); |
47
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
530 if (cached) |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
531 showBugs($(selector), cached); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
532 |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
533 $(selector).find("h2").addClass("loading"); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
534 |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
535 bugzilla.search(newTerms, |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
536 function(response) { |
67
d0f5f87e0b0a
dashboard stores per-user data in cache now.
Atul Varma <avarma@mozilla.com>
parents:
65
diff
changeset
|
537 cache.set(cacheKey, response.bugs); |
47
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
538 showBugs($(selector), response.bugs); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
539 $(selector).find("h2").removeClass("loading"); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
540 }); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
541 } |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
542 |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
543 function timeAgo(ms) { |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
544 var now = new Date(); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
545 var then = new Date(now - ms); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
546 return dateUtils.dateToISO8601(then); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
547 } |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
548 |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
549 const MS_PER_HOUR = 1000 * 60 * 60; |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
550 const MS_PER_DAY = MS_PER_HOUR * 24; |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
551 const MS_PER_WEEK = MS_PER_DAY * 7; |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
552 |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
553 var defaults = { |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
554 changed_after: timeAgo(MS_PER_WEEK * 14) |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
555 }; |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
556 |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
557 function update(myUsername) { |
71
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
558 report("#code-reviews", myUsername, |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
559 {status: ["NEW", "UNCONFIRMED", "ASSIGNED", "REOPENED"], |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
560 flag_DOT_requestee: myUsername}); |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
561 |
67
d0f5f87e0b0a
dashboard stores per-user data in cache now.
Atul Varma <avarma@mozilla.com>
parents:
65
diff
changeset
|
562 report("#assigned-bugs", myUsername, |
47
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
563 {status: ["NEW", "UNCONFIRMED", "ASSIGNED", "REOPENED"], |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
564 email1: myUsername, |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
565 email1_type: "equals", |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
566 email1_assigned_to: 1}); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
567 |
67
d0f5f87e0b0a
dashboard stores per-user data in cache now.
Atul Varma <avarma@mozilla.com>
parents:
65
diff
changeset
|
568 report("#reported-bugs", myUsername, |
47
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
569 {status: ["NEW", "UNCONFIRMED", "ASSIGNED", "REOPENED"], |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
570 email1: myUsername, |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
571 email1_type: "equals", |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
572 email1_reporter: 1, |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
573 email2: myUsername, |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
574 email2_type: "not_equals", |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
575 email2_assigned_to: 1}); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
576 |
67
d0f5f87e0b0a
dashboard stores per-user data in cache now.
Atul Varma <avarma@mozilla.com>
parents:
65
diff
changeset
|
577 report("#cc-bugs", myUsername, |
47
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
578 {status: ["NEW", "UNCONFIRMED", "ASSIGNED", "REOPENED"], |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
579 email1: myUsername, |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
580 email1_type: "equals", |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
581 email1_cc: 1, |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
582 email2: myUsername, |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
583 email2_type: "not_equals", |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
584 email2_assigned_to: 1, |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
585 email2_reporter: 1}); |
71
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
586 |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
587 report("#fixed-bugs", myUsername, |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
588 {resolution: ["FIXED"], |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
589 changed_after: timeAgo(MS_PER_WEEK), |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
590 email1: myUsername, |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
591 email1_type: "equals", |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
592 email1_assigned_to: 1, |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
593 email1_reporter: 1, |
4ec651cc606e
we now only make one request at a time to the bugzilla server, which reduces app responsiveness but makes us less of a douche to the server.
Atul Varma <avarma@mozilla.com>
parents:
68
diff
changeset
|
594 email1_cc: 1}); |
47
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
595 }; |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
596 |
68 | 597 var refreshCommand = { |
598 name: "refresh-dashboard", | |
599 execute: function execute() { | |
600 var user = require("app/login").get(); | |
601 if (user.isLoggedIn) | |
602 update(user.username); | |
603 } | |
604 }; | |
605 | |
47
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
606 exports.init = function init() { |
68 | 607 require("app/commands").register(refreshCommand); |
47
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
608 require("app/login").whenChanged( |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
609 function changeSearchCriteria(user) { |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
610 if (user.isLoggedIn) { |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
611 update(user.username); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
612 } |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
613 }); |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
614 }; |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
43
diff
changeset
|
615 }; |