Commit 0caeb71b authored by Kuo Jen Wei's avatar Kuo Jen Wei Committed by Commit Bot

[CCA] Convert filenamer.js into ES6 module.

Bug: 141518780
Test: Pass closure compiler check, tast run <DUT> 'camera.CCAUI*' and
manually validate tooltips function of CCA works correctly.

Change-Id: I65f8286c208ba922b2d6574ab836e0b77a2a39d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1982341
Commit-Queue: Kuo Jen Wei <inker@chromium.org>
Auto-Submit: Kuo Jen Wei <inker@chromium.org>
Reviewed-by: default avatarShik Chen <shik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#727528}
parent 484b3c72
...@@ -14,6 +14,9 @@ js_type_check("closure_compile") { ...@@ -14,6 +14,9 @@ js_type_check("closure_compile") {
} }
js_library("filenamer") { js_library("filenamer") {
deps = [
"..:namespace",
]
} }
js_library("filesystem") { js_library("filesystem") {
......
...@@ -2,22 +2,47 @@ ...@@ -2,22 +2,47 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
'use strict'; /**
* The prefix of image files.
* @type {string}
*/
export const IMAGE_PREFIX = 'IMG_';
/**
* The prefix of video files.
* @type {string}
*/
export const VIDEO_PREFIX = 'VID_';
/**
* The suffix of burst image files.
* @type {string}
*/
const BURST_SUFFIX = '_BURST';
/** /**
* Namespace for the Camera app. * The suffix of cover image for a series of burst image files.
* @type {string}
*/ */
var cca = cca || {}; const BURST_COVER_SUFFIX = '_COVER';
/** /**
* Namespace for models. * Transforms from capture timestamp to datetime name.
* @param {number} timestamp Timestamp to be transformed.
* @return {string} Transformed datetime name.
*/ */
cca.models = cca.models || {}; function timestampToDatetimeName(timestamp) {
const pad = (n) => (n < 10 ? '0' : '') + n;
var date = new Date(timestamp);
return date.getFullYear() + pad(date.getMonth() + 1) + pad(date.getDate()) +
'_' + pad(date.getHours()) + pad(date.getMinutes()) +
pad(date.getSeconds());
}
/** /**
* Filenamer for single camera session. * Filenamer for single camera session.
*/ */
cca.models.Filenamer = class { export class Filenamer {
/** /**
* @param {number=} timestamp Timestamp of camera session. * @param {number=} timestamp Timestamp of camera session.
*/ */
...@@ -47,11 +72,9 @@ cca.models.Filenamer = class { ...@@ -47,11 +72,9 @@ cca.models.Filenamer = class {
n = n + ''; n = n + '';
return new Array(Math.max(0, width - n.length) + 1).join('0') + n; return new Array(Math.max(0, width - n.length) + 1).join('0') + n;
}; };
return cca.models.Filenamer.IMAGE_PREFIX + return IMAGE_PREFIX + timestampToDatetimeName(this.timestamp_) +
this.constructor.timestampToDatetimeName_(this.timestamp_) + BURST_SUFFIX + prependZeros(++this.burstCount_, 5) +
cca.models.Filenamer.BURST_SUFFIX + (isCover ? BURST_COVER_SUFFIX : '') + '.jpg';
prependZeros(++this.burstCount_, 5) +
(isCover ? cca.models.Filenamer.BURST_COVER_SUFFIX : '') + '.jpg';
} }
/** /**
...@@ -59,8 +82,7 @@ cca.models.Filenamer = class { ...@@ -59,8 +82,7 @@ cca.models.Filenamer = class {
* @return {string} New filename. * @return {string} New filename.
*/ */
newVideoName() { newVideoName() {
return cca.models.Filenamer.VIDEO_PREFIX + return VIDEO_PREFIX + timestampToDatetimeName(this.timestamp_) + '.mkv';
this.constructor.timestampToDatetimeName_(this.timestamp_) + '.mkv';
} }
/** /**
...@@ -68,22 +90,7 @@ cca.models.Filenamer = class { ...@@ -68,22 +90,7 @@ cca.models.Filenamer = class {
* @return {string} New filename. * @return {string} New filename.
*/ */
newImageName() { newImageName() {
return cca.models.Filenamer.IMAGE_PREFIX + return IMAGE_PREFIX + timestampToDatetimeName(this.timestamp_) + '.jpg';
this.constructor.timestampToDatetimeName_(this.timestamp_) + '.jpg';
}
/**
* Transforms from capture timestamp to datetime name.
* @param {number} timestamp Timestamp to be transformed.
* @return {string} Transformed datetime name.
* @private
*/
static timestampToDatetimeName_(timestamp) {
const pad = (n) => (n < 10 ? '0' : '') + n;
var date = new Date(timestamp);
return date.getFullYear() + pad(date.getMonth() + 1) + pad(date.getDate()) +
'_' + pad(date.getHours()) + pad(date.getMinutes()) +
pad(date.getSeconds());
} }
/** /**
...@@ -94,32 +101,11 @@ cca.models.Filenamer = class { ...@@ -94,32 +101,11 @@ cca.models.Filenamer = class {
static getMetadataName(imageName) { static getMetadataName(imageName) {
return imageName.replace(/\.[^/.]+$/, '.json'); return imageName.replace(/\.[^/.]+$/, '.json');
} }
}; }
/** /** @const */
* The prefix of image files. cca.models.Filenamer = Filenamer;
* @type {string} /** @const */
* @const cca.models.Filenamer.IMAGE_PREFIX = IMAGE_PREFIX;
*/ /** @const */
cca.models.Filenamer.IMAGE_PREFIX = 'IMG_'; cca.models.Filenamer.VIDEO_PREFIX = VIDEO_PREFIX;
/**
* The prefix of video files.
* @type {string}
* @const
*/
cca.models.Filenamer.VIDEO_PREFIX = 'VID_';
/**
* The suffix of burst image files.
* @type {string}
* @const
*/
cca.models.Filenamer.BURST_SUFFIX = '_BURST';
/**
* The suffix of cover image for a series of burst image files.
* @type {string}
* @const
*/
cca.models.Filenamer.BURST_COVER_SUFFIX = '_COVER';
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
var cca = { var cca = {
device: {}, device: {},
intent: {}, intent: {},
models: {},
mojo: {}, mojo: {},
nav: {}, nav: {},
perf: {}, perf: {},
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
<script type="module" src="../js/device/camera3_device_info.js"></script> <script type="module" src="../js/device/camera3_device_info.js"></script>
<script type="module" src="../js/device/constraints_preferrer.js"></script> <script type="module" src="../js/device/constraints_preferrer.js"></script>
<script defer src="../js/device/device_info_updater.js"></script> <script defer src="../js/device/device_info_updater.js"></script>
<script defer src="../js/models/filenamer.js"></script> <script type="module" src="../js/models/filenamer.js"></script>
<script defer src="../js/gallerybutton.js"></script> <script defer src="../js/gallerybutton.js"></script>
<script defer src="../js/models/filesystem.js"></script> <script defer src="../js/models/filesystem.js"></script>
<script defer src="../js/models/result_saver.js"></script> <script defer src="../js/models/result_saver.js"></script>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment