Browse Source

HUE-264. Add a timer filter that increments up every second.

Aaron Newton 15 years ago
parent
commit
02260325be

+ 34 - 0
apps/jframegallery/src/jframegallery/templates/timer.html

@@ -0,0 +1,34 @@
+{% comment %}
+Licensed to Cloudera, Inc. under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  Cloudera, Inc. licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
+<html>
+  <head>
+    <title>Timer</title>
+  </head>
+  <body>
+  <div class="jframe_padded">
+		<p>This filter creates a timer that counts up from zero (or some other value you specify). It uses "human" wording, so when it passes 59 seconds it reads "about a minute ago" and on to "an hour", "a day", etc.</p>
+		<p>Example from zero:
+			<span data-filters="Timer"></span>
+		</p>
+		<p>Example from Dec 31, 1999:
+			<span data-filters="Timer" data-start-time="12/31/1999 11:59pm"></span>
+		</p>
+  </div>
+</body>
+</html>

+ 44 - 0
desktop/core/static/js/Source/BehaviorFilters/Behavior.Timer.js

@@ -0,0 +1,44 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/*
+---
+description: Adds a timer that counts forward from zero or a given value.
+provides: [Behavior.Timer]
+requires: [Widgets/Behavior, More/Date.Extras]
+script: Behavior.Timer.js
+
+...
+*/
+
+Behavior.addGlobalFilters({
+
+	Timer: function(element, methods){
+		var start = element.getData('start-time');
+		if (start) start = Date.parse(start);
+		else start = new Date();
+		var timer = (function(){
+			var now = new Date();
+			var diff = start.diff(now, 'second');
+			if (diff > 60) element.set('html', start.timeDiffInWords());
+			else element.set('html', diff + ' sec');
+		}).periodical(100);
+		this.markForCleanup(element, function(){
+			$clear(timer);
+		});
+	}
+
+});

+ 1 - 0
desktop/core/static/js/Source/CCS/CCS.JFrame.js

@@ -59,6 +59,7 @@ requires:
  - /Behavior.SubmitOnChange
  - /Behavior.Tabs
  - /Behavior.Tips
+ - /Behavior.Timer
  - /CCS
 
 script: CCS.JFrame.js

+ 1 - 0
desktop/core/static/js/package.yml

@@ -72,5 +72,6 @@ sources: [
   Source/BehaviorFilters/Behavior.SubmitOnChange.js,
   Source/BehaviorFilters/Behavior.Tabs.js,
   Source/BehaviorFilters/Behavior.Tips.js,
+  Source/BehaviorFilters/Behavior.Timer.js,
 ]
 version: Unknown