Skip to content

Commit 60a718c

Browse files
committed
ui.9; statusSort, showKey, filter (#29, #73, #95, #101, #145, #192)
1 parent aaee402 commit 60a718c

File tree

9 files changed

+115
-24
lines changed

9 files changed

+115
-24
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ the stable release):
1818
```
1919
meteor add msgfmt:[email protected] # 2016-01-11
2020
meteor add msgfmt:[email protected]
21-
meteor add msgfmt:[email protected].8 # 2016-01-27
21+
meteor add msgfmt:[email protected].9 # 2016-01-27
2222
```
2323

2424
If you don't want the UI translator on production (i.e. no crowd translation),

msgfmt:ui-dev-only/.versions

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ [email protected]
4141
4242
4343
44-
45-
44+
45+
4646
nicolaslopezj:[email protected]
4747
4848

msgfmt:ui-dev-only/package.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Package.describe({
22
name: "msgfmt:ui-dev-only",
3-
version: "2.0.1",
3+
version: "2.0.2",
44
summary: "msgfmt-ui that is never deployed",
55
git: "https://github.com/gadicc/meteor-messageformat.git",
66
debugOnly: true
77
});
88

99
Package.onUse(function (api) {
10-
api.use('msgfmt:[email protected].8');
10+
api.use('msgfmt:[email protected].9');
1111
api.imply('msgfmt:ui');
1212
});

msgfmt:ui/.versions

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jag:[email protected]
3131
3232
3333
34-
local-test:msgfmt:[email protected].8
34+
local-test:msgfmt:[email protected].9
3535
3636
3737
@@ -42,7 +42,7 @@ [email protected]
4242
4343
4444
45-
45+
4646
nicolaslopezj:[email protected]
4747
4848

msgfmt:ui/History.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
## vNEXT
22

3+
## 2.0.0-preview.9
4+
5+
Misc features related to #29, #73, #95, #101, #145, #192:
6+
7+
* Feature: sort first by status (untrans, fuzzy, trans)
8+
* Feature: show file, allow sort by file
9+
* Feature: filter by key, file, orig, trans
10+
311
## 2.0.0-preview.8
412

513
* Feature: sort objects by key when saving mfAll.js (#195)

msgfmt:ui/lib/client.js

+70-15
Original file line numberDiff line numberDiff line change
@@ -199,23 +199,56 @@ Template.mfTransLang.helpers({
199199
var orig = mfPkg.native;
200200
var lang = RouterLayer.getParam('lang');
201201

202-
// summarise matching keys (orig + trans) to a single record
203-
var out = {}, strings = mfPkg.mfStrings.find({
202+
var query = {
204203
$and: [{$or: [{lang: orig}, {lang: lang}]},
205204
{removed: undefined}]
206-
}).fetch();
205+
};
206+
207+
var filter = Session.get('mfTransLangFilter');
208+
if (filter) {
209+
filter = new RegExp(filter, 'i');
210+
/*
211+
since we need to recheck later anyways, no point doing twice
212+
query.$and.push({
213+
$or: [
214+
{ key: filter },
215+
// { text: filter }, // cant do this here, need both langs
216+
{ file: filter }
217+
]
218+
});
219+
*/
220+
}
221+
222+
var out = {}, strings = mfPkg.mfStrings.find(query).fetch();
207223

224+
// summarise matching keys (orig + trans) to a single record
208225
_.each(strings, function(str) {
209226
if (!out[str.key])
210227
out[str.key] = { key: str.key };
211-
if (str.lang == orig)
228+
229+
if (str.lang == orig) {
212230
out[str.key].orig = str.text;
213-
else
231+
out[str.key].file = str.file;
232+
} else {
214233
out[str.key].trans = str.text;
234+
}
235+
215236
if (str.fuzzy)
216237
out[str.key].fuzzy = true;
217238
});
218239

240+
// reject non-matches (can only do after orig/trans merge)
241+
if (filter)
242+
_.each(out, function(str, i) {
243+
if (!(
244+
str.key.match(filter) ||
245+
str.file.match(filter) ||
246+
str.orig.match(filter) ||
247+
(str.trans && str.trans.match(filter))
248+
))
249+
delete out[i];
250+
});
251+
219252
strings = _.values(out);
220253
strings = sortStrings(strings);
221254

@@ -243,9 +276,15 @@ Template.mfTransLang.events({
243276
var key = tr.data('key');
244277
if (key) changeKey(key);
245278
},
279+
'click #translationStatusSort': function(event) {
280+
Session.set('translationStatusSort', event.currentTarget.checked);
281+
},
246282
'click #translationShowKey': function(event) {
247283
Session.set('translationShowKey', event.currentTarget.checked);
248284
},
285+
'click #translationShowFile': function(event) {
286+
Session.set('translationShowFile', event.currentTarget.checked);
287+
},
249288
'click #translationCaseInsensitiveOrdering': function(event) {
250289
Session.set('translationCaseInsensitiveOrdering', event.currentTarget.checked);
251290
},
@@ -262,15 +301,24 @@ Template.mfTransLang.events({
262301
},
263302
'keyup #mfTransDest': function(event) {
264303
unsavedDest = event.target.value;
304+
},
305+
'keyup #mfTransLangFilter': function(event) {
306+
Session.set('mfTransLangFilter', event.target.value);
265307
}
266308
});
267309

268310
Template.mfTransLang.helpers({
311+
statusSort: function() {
312+
return Session.get('translationStatusSort');
313+
},
269314
showKey: function() {
270315
return Session.get('translationShowKey');
271316
},
317+
showFile: function() {
318+
return Session.get('translationShowFile');
319+
},
272320
caseInsensitiveOrdering: function() {
273-
return Session.get('caseInsensitiveOrdering');
321+
return Session.get('translationCaseInsensitiveOrdering');
274322
},
275323
sortOrderHeaderClass: function(headerSortField) {
276324
var classes = 'translationSort';
@@ -323,24 +371,31 @@ Template.mfTransLang.helpers({
323371
},
324372
isCheckboxChecked: function(value) {
325373
return (value === true ? 'checked' : '');
374+
},
375+
mfTransLangFilter: function() {
376+
return Session.get('mfTransLangFilter');
326377
}
327378
});
328379

380+
Session.setDefault('translationSortField', 'orig');
381+
Session.setDefault('translationSortOrder', 'asc');
382+
Session.setDefault('translationStatusSort', true);
383+
Session.setDefault('translationCaseInsensitiveOrdering', false);
384+
329385
var sortStrings = function(strings) {
330386
var sortField = Session.get('translationSortField');
331387
var sortOrder = Session.get('translationSortOrder');
332-
if (!sortField) {
333-
Session.set('translationSortField', 'orig');
334-
sortField = 'orig';
335-
}
336-
if (!sortOrder) {
337-
Session.set('translationSortOrder', 'asc');
338-
sortOrder = 'asc';
339-
}
388+
var caseInsensitiveOrdering = Session.get('translationCaseInsensitiveOrdering');
389+
340390
return strings.sort(function(a, b) {
391+
if (Session.get('translationStatusSort')) {
392+
if (a.trans && !b.trans || b.fuzzy) return 1;
393+
if (!a.trans && b.trans || !b.fuzzy) return -1;
394+
return 0;
395+
}
396+
341397
var first = a[sortField];
342398
var second = b[sortField];
343-
var caseInsensitiveOrdering = Session.get('translationCaseInsensitiveOrdering');
344399
if (first && caseInsensitiveOrdering) first = first.toLowerCase();
345400
if (second && caseInsensitiveOrdering) second = second.toLowerCase();
346401
if (sortOrder === 'asc') {

msgfmt:ui/lib/ui.css

+8
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,11 @@ div.mfTransGraph.untrans { background: #800; border-right: 1px solid black; }
9494
height: 5em; width: 100%;
9595
margin-top: 5px;
9696
}
97+
98+
#mfTransLang .translationSort {
99+
cursor: pointer;
100+
}
101+
102+
#mfTransLang label[title] {
103+
cursor: help;
104+
}

msgfmt:ui/lib/ui.html

+20-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ <h2>{{mf 'mf_site_translations' 'Site Translations'}}</h2>
7373
<table>
7474
<thead>
7575
<tr>
76-
{{#if showKey}}
76+
{{#if showFile}}
77+
<th class="{{sortOrderHeaderClass 'file'}}" data-sortField="file">
78+
<a href="#">File</a>
79+
</th>
80+
{{/if}} {{#if showKey}}
7781
<th class="{{sortOrderHeaderClass 'key'}}" data-sortField="key">
7882
<a href="#">Key</a>
7983
</th>
@@ -92,6 +96,9 @@ <h2>{{mf 'mf_site_translations' 'Site Translations'}}</h2>
9296
<tbody>
9397
{{#each strings}}
9498
<tr data-key="{{key}}" class="{{stateClass}} {{isCurrent}}">
99+
{{#if showFile}}
100+
<td>{{file}}</td>
101+
{{/if}}
95102
{{#if showKey}}
96103
<td>{{key}}</td>
97104
{{/if}}
@@ -104,14 +111,26 @@ <h2>{{mf 'mf_site_translations' 'Site Translations'}}</h2>
104111
</div>
105112
</div>
106113
<p class='options'>
114+
<label title="Order by untrans, fuzzy, trans">
115+
<input type="checkbox" id="translationStatusSort" {{isCheckboxChecked statusSort}}>
116+
Sort first by Status
117+
</label>
107118
<label>
108119
<input type="checkbox" id="translationShowKey" {{isCheckboxChecked showKey}}>
109120
Show key
110121
</label>
122+
<label>
123+
<input type="checkbox" id="translationShowFile" {{isCheckboxChecked showFile}}>
124+
Show file
125+
</label>
111126
<label>
112127
<input type='checkbox' id='translationCaseInsensitiveOrdering' {{isCheckboxChecked caseInsensitiveOrdering}}>
113128
Case insensitive ordering
114129
</label>
130+
<label title="Only show matching key, file, orig, trans">
131+
Filter:
132+
<input id='mfTransLangFilter' type='text' value={{mfTransLangFilter}} />
133+
</label>
115134
<br />
116135
Keyboard shortcuts: Ctrl-up/down arrow (Win); Control-Command-up/down arrow (Mac)
117136
<br />

msgfmt:ui/package.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package.describe({
22
name: "msgfmt:ui",
3-
version: "2.0.0-preview.8",
3+
version: "2.0.0-preview.9",
44
summary: "messageformat: translation UI",
55
git: "https://github.com/gadicc/meteor-messageformat.git",
66
});
@@ -15,6 +15,7 @@ Package.onUse(function (api) {
1515

1616
api.use('mongo');
1717
api.use('msgfmt:[email protected]');
18+
api.use('session', 'client');
1819

1920
api.addFiles('lib/common.js');
2021
api.addFiles('lib/server.js', 'server');

0 commit comments

Comments
 (0)