Browse Source

Merge pull request #7 from newsdev/feature/semantic_filenamees

James Thomas 7 years ago
parent
commit
2322087dbc
2 changed files with 29 additions and 9 deletions
  1. 28 7
      client/index.js
  2. 1 2
      client/video.js

+ 28 - 7
client/index.js View File

2
     $ = require("jquery"),
2
     $ = require("jquery"),
3
     preview = require("./preview.js"),
3
     preview = require("./preview.js"),
4
     video = require("./video.js"),
4
     video = require("./video.js"),
5
-    audio = require("./audio.js");
5
+    audio = require("./audio.js"),
6
+    timestamp,
7
+    identifier;
8
+
9
+
10
+function addZero (digit) {
11
+  if (digit.toString().length === 1) {
12
+    return '0' + digit.toString();
13
+  }
14
+  else {
15
+    return digit.toString();
16
+  }
17
+}
18
+
19
+function timestamp () {
20
+  var d = new Date();
21
+
22
+  return addZero(d.getMonth() + 1)
23
+  + addZero(d.getDate())
24
+  + d.getFullYear().toString().slice(2,4) + '_'
25
+  + addZero(d.getHours())
26
+  + addZero(d.getMinutes())
27
+  + addZero(d.getSeconds()) + '_';
28
+}
29
+
6
 
30
 
7
 d3.json("/settings/labels.json", function(err, labels){
31
 d3.json("/settings/labels.json", function(err, labels){
8
 
32
 
61
       citation = preview.citation(),
85
       citation = preview.citation(),
62
       label = preview.label(),
86
       label = preview.label(),
63
       selection = preview.selection(),
87
       selection = preview.selection(),
64
-      file = preview.file(),
65
-      identifier;
88
+      file = preview.file();
66
 
89
 
67
-  // for easy-to-scan filenames
68
-  identifier = caption.replace(/\s+/g, '_').replace(/\'|\"|\.|\?|\!/g, '').toLowerCase().slice(0, 20);
90
+  // combine timestamp and caption for easy-to-scan filenames
91
+  identifier = timestamp() + preview.caption().replace(/\s+/g, '_').replace(/\'|\"|\.|\?|\!/g, '').toLowerCase().slice(0, 20);
69
 
92
 
70
   if (!file) {
93
   if (!file) {
71
     d3.select("#row-audio").classed("error", true);
94
     d3.select("#row-audio").classed("error", true);
121
 }
144
 }
122
 
145
 
123
 function poll(id) {
146
 function poll(id) {
124
-  var identifier = preview.caption().replace(/\s+/g, '_').replace(/\'|\"|\.|\?|\!/g, '').toLowerCase().slice(0, 20);
125
-
126
   setTimeout(function(){
147
   setTimeout(function(){
127
     $.ajax({
148
     $.ajax({
128
       url: "/status/" + id + "/",
149
       url: "/status/" + id + "/",

+ 1 - 2
client/video.js View File

15
 
15
 
16
 function update(url, name) {
16
 function update(url, name) {
17
 
17
 
18
-  var timestamp = d3.timeFormat("%m%d%y_AG_")(new Date).toLowerCase(),
19
-      filename = timestamp + (name || "Audiogram") + ".mp4";
18
+  var filename = (name || "Audiogram") + ".mp4";
20
 
19
 
21
   d3.select("#download")
20
   d3.select("#download")
22
     .attr("download", filename)
21
     .attr("download", filename)