define( [ "jquery", "ui/widgets/slider" ], function( $ ) { module( "slider: events" ); //Specs from http://wiki.jqueryui.com/Slider#specs //"change callback: triggers when the slider has stopped moving and has a new // value (even if same as previous value), via mouse(mouseup) or keyboard(keyup) // or value method/option" test( "mouse based interaction", function() { expect( 4 ); var element = $( "#slider1" ) .slider( { start: function( event ) { equal( event.originalEvent.type, "mousedown", "start triggered by mousedown" ); }, slide: function( event ) { equal( event.originalEvent.type, "mousemove", "slider triggered by mousemove" ); }, stop: function( event ) { equal( event.originalEvent.type, "mouseup", "stop triggered by mouseup" ); }, change: function( event ) { equal( event.originalEvent.type, "mouseup", "change triggered by mouseup" ); } } ); element.find( ".ui-slider-handle" ).eq( 0 ) .simulate( "drag", { dx: 10, dy: 10 } ); } ); test( "keyboard based interaction", function() { expect( 3 ); // Test keyup at end of handle slide (keyboard) var element = $( "#slider1" ) .slider( { start: function( event ) { equal( event.originalEvent.type, "keydown", "start triggered by keydown" ); }, slide: function() { ok( false, "Slider never triggered by keys" ); }, stop: function( event ) { equal( event.originalEvent.type, "keyup", "stop triggered by keyup" ); }, change: function( event ) { equal( event.originalEvent.type, "keyup", "change triggered by keyup" ); } } ); element.find( ".ui-slider-handle" ).eq( 0 ) .simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ) .simulate( "keypress", { keyCode: $.ui.keyCode.LEFT } ) .simulate( "keyup", { keyCode: $.ui.keyCode.LEFT } ); } ); test( "programmatic event triggers", function() { expect( 6 ); // Test value method var element = $( "
" ) .slider( { change: function() { ok( true, "change triggered by value method" ); } } ) .slider( "value", 0 ); // Test values method element = $( "
" ) .slider( { values: [ 10, 20 ], change: function() { ok( true, "change triggered by values method" ); } } ) .slider( "values", [ 80, 90 ] ); // Test value option element = $( "
" ) .slider( { change: function() { ok( true, "change triggered by value option" ); } } ) .slider( "option", "value", 0 ); // Test values option element = $( "
" ) .slider( { values: [ 10, 20 ], change: function() { ok( true, "change triggered by values option" ); } } ) .slider( "option", "values", [ 80, 90 ] ); } ); test( "mouse based interaction part two: when handles overlap", function() { expect( 6 ); var element = $( "#slider1" ) .slider( { values: [ 0, 0, 0 ], start: function( event, ui ) { equal( handles.index( ui.handle ), 2, "rightmost handle activated when overlapping at minimum (#3736)" ); } } ), handles = element.find( ".ui-slider-handle" ); handles.eq( 0 ).simulate( "drag", { dx: 10 } ); element.slider( "destroy" ); element = $( "#slider1" ) .slider( { values: [ 10, 10, 10 ], max: 10, start: function( event, ui ) { equal( handles.index( ui.handle ), 0, "leftmost handle activated when overlapping at maximum" ); } } ), handles = element.find( ".ui-slider-handle" ); handles.eq( 0 ).simulate( "drag", { dx: -10 } ); element.slider( "destroy" ); element = $( "#slider1" ) .slider( { values: [ 19, 20 ] } ), handles = element.find( ".ui-slider-handle" ); handles.eq( 0 ).simulate( "drag", { dx: 10 } ); element.one( "slidestart", function( event, ui ) { equal( handles.index( ui.handle ), 0, "left handle activated if left was moved last" ); } ); handles.eq( 0 ).simulate( "drag", { dx: 10 } ); element.slider( "destroy" ); element = $( "#slider1" ) .slider( { values: [ 19, 20 ] } ), handles = element.find( ".ui-slider-handle" ); handles.eq( 1 ).simulate( "drag", { dx: -10 } ); element.one( "slidestart", function( event, ui ) { equal( handles.index( ui.handle ), 1, "right handle activated if right was moved last (#3467)" ); } ); handles.eq( 0 ).simulate( "drag", { dx: 10 } ); element = $( "#slider1" ) .slider( { range: true, min: 0, max: 100, values: [ 0, 50 ] } ), handles = element.find( ".ui-slider-handle" ); element.slider( "option", { values: [ 100, 100 ] } ); handles.eq( 0 ).simulate( "drag", { dx: -10 } ); equal( element.slider( "values" )[ 0 ], 99, "setting both values of range slider to the maximum doesn't lock slider" ); element.slider( "option", { values: [ 0, 0 ] } ); handles.eq( 1 ).simulate( "drag", { dx: 10 } ); equal( element.slider( "values" )[ 1 ], 1, "setting both values of range slider to the minimum doesn't lock slider" ); } ); test( "event data", function() { expect( 6 ); var slideHandleIndex = 3, values = [ 8, 9, 7, 4 ], newValues = [ 8, 9, 7, 5 ], element = $( "#slider1" ) .slider( { values: values, start: function( event, ui ) { deepEqual( ui, expectedUiHash, "passing ui to start event" ); }, slide: function( event, ui ) { deepEqual( ui, expectedChangedUiHash, "passing ui to slide event" ); }, stop: function( event, ui ) { deepEqual( ui, expectedChangedUiHash, "passing ui to stop event" ); }, change: function( event, ui ) { deepEqual( ui, expectedChangedUiHash, "passing ui to change event" ); } } ), handles = element.find( ".ui-slider-handle" ), expectedUiHash = { handle: handles.eq( slideHandleIndex )[ 0 ], handleIndex: slideHandleIndex, values: values, value: values[ slideHandleIndex ] }, expectedChangedUiHash = $.extend( {}, expectedUiHash, { values: newValues, value: newValues[ slideHandleIndex ] } ); handles.eq( slideHandleIndex ).simulate( "drag", { dx: 10 } ); element.slider( "destroy" ); element = $( "#slider1" ).slider( { min: 0, max: 100, value: 1, slide: function( event, ui ) { equal( ui.value, 0, "should pass 0 value if slider reaches it" ); } } ); handles = element.find( ".ui-slider-handle" ); handles.eq( 0 ).simulate( "drag", { dx: -10 } ); element.slider( "destroy" ); element = $( "#slider1" ).slider( { min: 0, max: 100, values: [ 1, 2 ], slide: function( event, ui ) { equal( ui.value, 0, "should pass 0 value if one of handles reaches it" ); } } ); handles = element.find( ".ui-slider-handle" ); handles.eq( 0 ).simulate( "drag", { dx: -10 } ); } ); } ); _close'>artonge/feat/reset_route_when_sidebar_and_viewer_are_close Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Console/TimestampFormatter.php
blob: 9ced9e18b31f54723f2f1adcf8e83a38058b29fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
 * @copyright Copyright (c) 2016, ownCloud, Inc.
 *
 * @author Joas Schilling <coding@schilljs.com>
 *
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

namespace OC\Console;


use OCP\IConfig;
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Symfony\Component\Console\Formatter\OutputFormatterStyleInterface;

class TimestampFormatter implements OutputFormatterInterface {
	/** @var IConfig */
	protected $config;

	/** @var OutputFormatterInterface */
	protected $formatter;

	/**
	 * @param IConfig $config
	 * @param OutputFormatterInterface $formatter
	 */
	public function __construct(IConfig $config, OutputFormatterInterface $formatter) {
		$this->config = $config;
		$this->formatter = $formatter;
	}

	/**
	 * Sets the decorated flag.
	 *
	 * @param bool $decorated Whether to decorate the messages or not
	 */
	public function setDecorated($decorated) {
		$this->formatter->setDecorated($decorated);
	}

	/**
	 * Gets the decorated flag.
	 *
	 * @return bool true if the output will decorate messages, false otherwise
	 */
	public function isDecorated() {
		return $this->formatter->isDecorated();
	}

	/**
	 * Sets a new style.
	 *
	 * @param string $name The style name
	 * @param OutputFormatterStyleInterface $style The style instance
	 */
	public function setStyle($name, OutputFormatterStyleInterface $style) {
		$this->formatter->setStyle($name, $style);
	}

	/**
	 * Checks if output formatter has style with specified name.
	 *
	 * @param string $name
	 * @return bool
	 */
	public function hasStyle($name) {
		return $this->formatter->hasStyle($name);
	}

	/**
	 * Gets style options from style with specified name.
	 *
	 * @param string $name
	 * @return OutputFormatterStyleInterface
	 * @throws \InvalidArgumentException When style isn't defined
	 */
	public function getStyle($name) {
		return $this->formatter->getStyle($name);
	}

	/**
	 * Formats a message according to the given styles.
	 *
	 * @param string $message The message to style
	 * @return string The styled message, prepended with a timestamp using the
	 * log timezone and dateformat, e.g. "2015-06-23T17:24:37+02:00"
	 */
	public function format($message) {

		$timeZone = $this->config->getSystemValue('logtimezone', 'UTC');
		$timeZone = $timeZone !== null ? new \DateTimeZone($timeZone) : null;

		$time = new \DateTime('now', $timeZone);
		$timestampInfo = $time->format($this->config->getSystemValue('logdateformat', \DateTime::ATOM));

		return $timestampInfo . ' ' . $this->formatter->format($message);
	}
}