Revize 34c0b905
Přidáno uživatelem Jiří Noháč před téměř 5 roky(ů)
app/Http/Controllers/CategoriesController.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
namespace App\Http\Controllers; |
|
4 |
|
|
5 |
use App\ArtefactCategory; |
|
6 |
use App\Category; |
|
7 |
use Illuminate\Support\Facades\Auth; |
|
8 |
use App\User; |
|
9 |
|
|
10 |
class CategoriesController extends Controller |
|
11 |
{ |
|
12 |
public function __construct() |
|
13 |
{ |
|
14 |
$this->middleware('auth'); |
|
15 |
} |
|
16 |
|
|
17 |
public function calculateClusters($categoriesCount) |
|
18 |
{ |
|
19 |
if(isset($categoriesCount)) |
|
20 |
{ |
|
21 |
$min = PHP_INT_MAX; |
|
22 |
$max = PHP_INT_MIN; |
|
23 |
foreach($categoriesCount as $category) |
|
24 |
{ |
|
25 |
$c = count($category); |
|
26 |
if($c < $min) |
|
27 |
{ |
|
28 |
$min = $c; |
|
29 |
} |
|
30 |
|
|
31 |
if($c > $max) |
|
32 |
{ |
|
33 |
$max = $c; |
|
34 |
} |
|
35 |
} |
|
36 |
$center = $min + (($max - $min)/2); |
|
37 |
return array($min, $center, $max); |
|
38 |
} |
|
39 |
else |
|
40 |
{ |
|
41 |
return null; |
|
42 |
} |
|
43 |
} |
|
44 |
|
|
45 |
/** |
|
46 |
* Display a listing of the resource. |
|
47 |
* |
|
48 |
* @return \Illuminate\Http\Response |
|
49 |
*/ |
|
50 |
public function index() |
|
51 |
{ |
|
52 |
if(isset(Auth::user()->id)) |
|
53 |
{ |
|
54 |
$userId = Auth::user()->id; |
|
55 |
|
|
56 |
$categoryNames = Category::all(); |
|
57 |
$countCategory = count($categoryNames); |
|
58 |
$categories = array(); |
|
59 |
for($i = 1; $i <= $countCategory;$i++) |
|
60 |
{ |
|
61 |
array_push($categories, ArtefactCategory::where('category_id', $i)->get()); |
|
62 |
} |
|
63 |
$clusters = $this->calculateClusters($categories); |
|
64 |
|
|
65 |
$categorySizes = array(); |
|
66 |
if(isset($clusters)) |
|
67 |
{ |
|
68 |
foreach($categories as $category) |
|
69 |
{ |
|
70 |
$c = count($category); |
|
71 |
$type1 = abs($clusters['0'] - $c); |
|
72 |
$type2 = abs($clusters['1'] - $c); |
|
73 |
$type3 = abs($clusters['2'] - $c); |
|
74 |
|
|
75 |
if($type1 <= $type2 && $type1 <= $type3) |
|
76 |
{ |
|
77 |
array_push($categorySizes, 1); |
|
78 |
} |
|
79 |
else if($type2 <= $type1 && $type2 <= $type3) |
|
80 |
{ |
|
81 |
array_push($categorySizes, 2); |
|
82 |
} |
|
83 |
else |
|
84 |
{ |
|
85 |
array_push($categorySizes, 3); |
|
86 |
} |
|
87 |
} |
|
88 |
} |
|
89 |
|
|
90 |
$data = array( |
|
91 |
'title' => 'Categories', |
|
92 |
'user' => User::find($userId), |
|
93 |
'count' => $countCategory, |
|
94 |
'categories' => $categories, |
|
95 |
'categorySizes' => $categorySizes, |
|
96 |
'categoryNames' => $categoryNames |
|
97 |
); |
|
98 |
return view('categories.index') -> with($data); |
|
99 |
} |
|
100 |
else |
|
101 |
{ |
|
102 |
$data = array( |
|
103 |
'title' => 'Welcome to the MERLOT page', |
|
104 |
); |
|
105 |
return view('pages.index') -> with($data); |
|
106 |
} |
|
107 |
} |
|
108 |
} |
resources/sass/_custom.scss | ||
---|---|---|
1 | 1 |
// Ready for custom styling |
2 |
|
|
3 |
body |
|
4 |
{ |
|
5 |
background-color: $cusBlack; |
|
6 |
} |
|
7 |
|
|
8 |
.head-title.text-center h1 |
|
9 |
{ |
|
10 |
color: $cusWhite; |
|
11 |
font-family: Avenir; |
|
12 |
font-size: 60pt; |
|
13 |
font-weight: bold; |
|
14 |
letter-spacing: 3px; |
|
15 |
} |
|
16 |
|
|
17 |
.bouton-image:before |
|
18 |
{ |
|
19 |
content: ""; |
|
20 |
width: 100px; |
|
21 |
height: 100px; |
|
22 |
display: inline-block; |
|
23 |
margin-right: 5px; |
|
24 |
vertical-align: text-top; |
|
25 |
background-color: transparent; |
|
26 |
background-position : center center; |
|
27 |
background-repeat:no-repeat; |
|
28 |
} |
|
29 |
|
|
30 |
.bouton-image |
|
31 |
{ |
|
32 |
background-color: transparent; |
|
33 |
border-color: transparent; |
|
34 |
} |
|
35 |
|
|
36 |
.monBouton:before |
|
37 |
{ |
|
38 |
background-image : url(../images/Button_Arrow_Small.png); |
|
39 |
} |
|
40 |
|
|
41 |
.monBouton:hover |
|
42 |
{ |
|
43 |
background-color: transparent; |
|
44 |
border-color: $cusBrown3; |
|
45 |
} |
|
46 |
|
|
47 |
.monBouton:focus |
|
48 |
{ |
|
49 |
background-color: transparent; |
|
50 |
border-color: $cusBrown3; |
|
51 |
outline: none !important; |
|
52 |
box-shadow: none !important; |
|
53 |
} |
|
54 |
|
|
55 |
.monBouton:active |
|
56 |
{ |
|
57 |
background-color: transparent !important; |
|
58 |
border-color: transparent !important; |
|
59 |
outline: none !important; |
|
60 |
box-shadow: none !important; |
|
61 |
} |
|
62 |
|
|
63 |
.content { |
|
64 |
position: relative; |
|
65 |
} |
|
66 |
|
|
67 |
//Circle style button |
|
68 |
.btn-circle.rounded-circle.btn-sm |
|
69 |
{ |
|
70 |
position: absolute; |
|
71 |
width: 120px; |
|
72 |
height: 120px; |
|
73 |
padding: 6px 0px; |
|
74 |
border-radius: 15px; |
|
75 |
font-size: 16px; |
|
76 |
text-align: center; |
|
77 |
background-color: $cusBlack; |
|
78 |
border-color: $cusBrown3; |
|
79 |
border-width: 5px; |
|
80 |
color:$cusBrown3; |
|
81 |
outline: none !important; |
|
82 |
box-shadow: none !important; |
|
83 |
} |
|
84 |
|
|
85 |
.btn-circle.rounded-circle.btn-sm:active |
|
86 |
{ |
|
87 |
background-color: $cusBrown2; |
|
88 |
border-color: $cusBrown3; |
|
89 |
outline: none !important; |
|
90 |
box-shadow: none !important; |
|
91 |
color:$cusBlack; |
|
92 |
} |
|
93 |
|
|
94 |
.btn-circle.rounded-circle.btn-dm |
|
95 |
{ |
|
96 |
position: absolute; |
|
97 |
width: 240px; |
|
98 |
height: 240px; |
|
99 |
padding: 6px 0px; |
|
100 |
border-radius: 15px; |
|
101 |
font-size: 16px; |
|
102 |
text-align: center; |
|
103 |
background-color: $cusBlack; |
|
104 |
border-color: $cusBrown3; |
|
105 |
color:$cusBrown3; |
|
106 |
border-width: 5px; |
|
107 |
outline: none !important; |
|
108 |
box-shadow: none !important; |
|
109 |
} |
|
110 |
.btn-circle.rounded-circle.btn-dm:active |
|
111 |
{ |
|
112 |
background-color: $cusBrown2; |
|
113 |
border-color: $cusBrown3; |
|
114 |
outline: none !important; |
|
115 |
box-shadow: none !important; |
|
116 |
color:$cusBlack; |
|
117 |
} |
|
118 |
|
|
119 |
.btn-circle.rounded-circle.btn-xl |
|
120 |
{ |
|
121 |
position: absolute; |
|
122 |
width: 360px; |
|
123 |
height: 360px; |
|
124 |
padding: 6px 0px; |
|
125 |
border-radius: 15px; |
|
126 |
font-size: 16px; |
|
127 |
text-align: center; |
|
128 |
background-color: $cusBlack; |
|
129 |
border-color: $cusBrown3; |
|
130 |
color:$cusBrown3; |
|
131 |
border-width: 5px; |
|
132 |
outline: none !important; |
|
133 |
box-shadow: none !important; |
|
134 |
} |
|
135 |
.btn-circle.rounded-circle.btn-xl:active |
|
136 |
{ |
|
137 |
background-color: $cusBrown2; |
|
138 |
border-color: $cusBrown3; |
|
139 |
outline: none !important; |
|
140 |
box-shadow: none !important; |
|
141 |
color:$cusBlack; |
|
142 |
} |
|
143 |
|
|
144 |
@media only screen and (max-width: 540px) |
|
145 |
{ |
|
146 |
.head-title.text-center h1 |
|
147 |
{ |
|
148 |
font-size: 45pt; |
|
149 |
} |
|
150 |
|
|
151 |
.btn-circle.rounded-circle.btn-sm |
|
152 |
{ |
|
153 |
width: 90px; |
|
154 |
height: 90px; |
|
155 |
} |
|
156 |
|
|
157 |
.btn-circle.rounded-circle.btn-dm |
|
158 |
{ |
|
159 |
width: 130px; |
|
160 |
height: 130px; |
|
161 |
} |
|
162 |
|
|
163 |
.btn-circle.rounded-circle.btn-xl |
|
164 |
{ |
|
165 |
width: 180px; |
|
166 |
height: 180px; |
|
167 |
} |
|
168 |
} |
resources/sass/_variables.scss | ||
---|---|---|
17 | 17 |
$green: #38c172; |
18 | 18 |
$teal: #4dc0b5; |
19 | 19 |
$cyan: #6cb2eb; |
20 |
|
|
21 |
// Custom colors |
|
22 |
$cusWhite: #ffffff; |
|
23 |
$cusBrown1: #ddd1b9; |
|
24 |
$cusBrown2: #efdab3; |
|
25 |
$cusBrown3: #ead4b0; |
|
26 |
$cusBlack: #272727; |
|
27 |
|
resources/sass/app.scss | ||
---|---|---|
6 | 6 |
|
7 | 7 |
// Bootstrap |
8 | 8 |
@import '~bootstrap/scss/bootstrap'; |
9 |
|
|
10 |
@import 'custom'; |
resources/views/categories/index.blade.php | ||
---|---|---|
1 |
@extends('layouts.art') |
|
2 |
|
|
3 |
@section('title', 'Categories') |
|
4 |
|
|
5 |
@section('content') |
|
6 |
@if(isset($user)) |
|
7 |
{{--<p><?php dd($categories); ?></p>--}} |
|
8 |
<div> |
|
9 |
<button type="button" class="btn btn-primary bouton-image monBouton"></button> |
|
10 |
</div> |
|
11 |
<div class="head-title text-center"> |
|
12 |
<h1>choose a few topics</h1> |
|
13 |
</div> |
|
14 |
<div class="content" id="canvas"> |
|
15 |
{{--@for($k = 1; $k <= count($categories);$k++)--}} |
|
16 |
@for($k = 1; $k <= 10;$k++) |
|
17 |
@if($categorySizes[$k-1] == 1) |
|
18 |
<button type="button" class="btn btn-primary btn-circle rounded-circle btn-sm" id="cat-{{$k}}">{{$categoryNames[$k-1]->nameEN}}</button> |
|
19 |
@elseif($categorySizes[$k-1] == 2) |
|
20 |
<button type="button" class="btn btn-primary btn-circle rounded-circle btn-dm" id="cat-{{$k}}">{{$categoryNames[$k-1]->nameEN}}</button> |
|
21 |
@else |
|
22 |
<button type="button" class="btn btn-primary btn-circle rounded-circle btn-xl" id="cat-{{$k}}">{{$categoryNames[$k-1]->nameEN}}</button> |
|
23 |
@endif |
|
24 |
@endfor |
|
25 |
</div> |
|
26 |
<script> |
|
27 |
function randomCategoryPos(name, countButtons) |
|
28 |
{ |
|
29 |
var DISTANCE = 360; |
|
30 |
var MAX_DISTANCE = 3.5 * DISTANCE; |
|
31 |
var sWidth = screen.width; |
|
32 |
var positionsX = []; |
|
33 |
var positionsY = []; |
|
34 |
var types = []; |
|
35 |
var offset = 50; |
|
36 |
|
|
37 |
if(sWidth <= 540) |
|
38 |
{ |
|
39 |
sWidth -= 100; |
|
40 |
DISTANCE = 190; |
|
41 |
MAX_DISTANCE = 3.5 * DISTANCE; |
|
42 |
offset = 25; |
|
43 |
} |
|
44 |
else |
|
45 |
{ |
|
46 |
if(sWidth > 720) |
|
47 |
{ |
|
48 |
sWidth = 720; |
|
49 |
} |
|
50 |
} |
|
51 |
console.log(DISTANCE+ "dis\n"); |
|
52 |
console.log(MAX_DISTANCE+ "max_dis\n"); |
|
53 |
for(var i = 0; i < countButtons; i++) |
|
54 |
{ |
|
55 |
var size = document.getElementById(name + (i+1)).className; |
|
56 |
var type; |
|
57 |
if(size.includes("btn-sm")) |
|
58 |
{ |
|
59 |
if(sWidth <= 540) |
|
60 |
{ |
|
61 |
type = 45; |
|
62 |
} |
|
63 |
else |
|
64 |
{ |
|
65 |
type = 60; |
|
66 |
} |
|
67 |
} |
|
68 |
else if(size.includes("btn-dm")) |
|
69 |
{ |
|
70 |
if(sWidth <= 540) |
|
71 |
{ |
|
72 |
type = 65; |
|
73 |
} |
|
74 |
else |
|
75 |
{ |
|
76 |
type = 120; |
|
77 |
} |
|
78 |
} |
|
79 |
else |
|
80 |
{ |
|
81 |
if(sWidth <= 540) |
|
82 |
{ |
|
83 |
type = 90; |
|
84 |
} |
|
85 |
else |
|
86 |
{ |
|
87 |
type = 180; |
|
88 |
} |
|
89 |
} |
|
90 |
console.log(type + "<br>"); |
|
91 |
//document.write(type + "<br>"); |
|
92 |
|
|
93 |
var done = true; |
|
94 |
var topS; |
|
95 |
var rightS; |
|
96 |
while(done) |
|
97 |
{ |
|
98 |
if(i == 0) |
|
99 |
{ |
|
100 |
topS = offset + type; |
|
101 |
} |
|
102 |
else |
|
103 |
{ |
|
104 |
topS = (Math.floor(Math.random() * 2048) + offset) + type; |
|
105 |
} |
|
106 |
rightS = (Math.floor(Math.random() * sWidth) + 1) + type; |
|
107 |
console.log(topS + " " + rightS + "nn<br>"); |
|
108 |
|
|
109 |
//Check distancing from other circles |
|
110 |
var okay = true; |
|
111 |
for(var k = 0; k < positionsX.length; k++) |
|
112 |
{ |
|
113 |
var powX = Math.abs(positionsX[k] - topS); |
|
114 |
var powY = Math.abs(positionsY[k] - rightS); |
|
115 |
var tmp = Math.sqrt((powX*powX) + (powY*powY)); |
|
116 |
console.log(tmp+ "tmp<br>"); |
|
117 |
if(tmp < DISTANCE) |
|
118 |
{ |
|
119 |
okay = false; |
|
120 |
break; |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
if(okay) |
|
125 |
{ |
|
126 |
done = false; |
|
127 |
} |
|
128 |
} |
|
129 |
|
|
130 |
//document.write("<br>"); |
|
131 |
positionsX.push(topS); |
|
132 |
positionsY.push(rightS); |
|
133 |
types.push(type); |
|
134 |
} |
|
135 |
|
|
136 |
for(var i = 1; i <= countButtons; i++) |
|
137 |
{ |
|
138 |
document.getElementById(name + i).style.top = (positionsX[i-1] - types[i-1]) + "px"; |
|
139 |
document.getElementById(name + i).style.right = (positionsY[i-1] - types[i-1]) + "px"; |
|
140 |
} |
|
141 |
} |
|
142 |
|
|
143 |
var countButtons = document.getElementById("canvas").getElementsByTagName('button').length; |
|
144 |
randomCategoryPos("cat-", countButtons); |
|
145 |
</script> |
|
146 |
@else |
|
147 |
<ul class="list-group"> |
|
148 |
<li class="list-group-item"> |
|
149 |
<h3>Not found the USER in the database with number id {{$user->id}}!</h3> |
|
150 |
</li> |
|
151 |
</ul> |
|
152 |
@endif |
|
153 |
@endsection |
Také k dispozici: Unified diff
Issue #7850 @10h
Vytvoreni stranky kategorii podle navrhu rozlozeni dle umelecke specifikace. Stranka po jejimz nacteni zobrazi bubliny reprezentujici konkretni kategorie artefaktu. Kazda bublina ma tri velikosti, dle rozzareni do tri kategorii podle poctu artefaktu v konkretni kategorii. Bubliny jsou nahodne rozhazene po strance, pricemz by se zadne nemely krizit. Co se tyce fontu Avenir Black, je to momentalne reseno primem nainstalovanim fontu do PC a nactenim pres "font-family".