Completed
Push — styling ( 65b228 )
by Jeroen De
04:06
created

GeoJsonMapPageUi::forExistingPage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\Presentation;
6
7
use Html;
8
9
class GeoJsonMapPageUi {
10
11
	private $json;
12
13 1
	public static function forExistingPage( string $mapJson ): self {
14 1
		return new self( $mapJson );
15
	}
16
17 1
	private function __construct( ?string $json ) {
18 1
		$this->json = $json;
19 1
	}
20
21 1
	public function addToOutput( OutputFacade $output ) {
22 1
		$leafletPath = $GLOBALS['wgScriptPath'] . '/extensions/Maps/resources/lib/leaflet';
23
24 1
		$output->addHeadItem(
25 1
			'MapsGeoJsonHeadItem',
26 1
			Html::linkedStyle( "$leafletPath/leaflet.css" ) . Html::linkedScript( "$leafletPath/leaflet.js" )
27
		);
28
29 1
		$output->addHTML( $this->getJavascript() . $this->getHtml() );
30 1
		$output->addModules( 'ext.maps.geojson.page' );
31 1
	}
32
33 1
	private function getJavascript(): string {
34 1
		return Html::element(
35 1
			'script',
36 1
			[],
37 1
			$this->getJsonJs()
38
		);
39
	}
40
41 1
	private function getJsonJs(): string {
42
		return 'var GeoJson ='
43 1
			. $this->json
44 1
			. ';';
45
	}
46
47 1
	private function getHtml(): string {
48 1
		return $this->wrapHtmlInThumbDivs(
49 1
			Html::rawElement(
50 1
				'div',
51
				[
52 1
					'id' => 'GeoJsonMap',
53
					'style' => 'width: 100%; height: 600px; background-color: #eeeeee; overflow: hidden;',
54
					'class' => 'maps-map maps-leaflet maps-geojson-editor'
55
				],
56 1
				Html::element(
57 1
					'div',
58
					[
59 1
						'class' => 'maps-loading-message'
60
					],
61 1
					wfMessage( 'maps-loading-map' )->inContentLanguage()->text()
62
				)
63
			)
64
		);
65
	}
66
67 1
	private function wrapHtmlInThumbDivs( string $html ): string {
68 1
		return Html::rawElement(
69 1
			'div',
70
			[
71 1
				'class' => 'thumb'
72
			],
73 1
			Html::rawElement(
74 1
				'div',
75
				[
76 1
					'class' => 'thumbinner'
77
				],
78
				$html
79
			)
80
		);
81
	}
82
83
}
84