Skip to content

Commit

Permalink
backgrounds madness
Browse files Browse the repository at this point in the history
  • Loading branch information
KiboOst committed Jan 29, 2021
1 parent f42b4df commit 258c227
Show file tree
Hide file tree
Showing 15 changed files with 270 additions and 70 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -18,6 +18,7 @@ data/*
!data/.htaccess
!data/php
!data/3d
!data/backgrounds
!data/view
!data/img
!data/object
Expand Down
68 changes: 60 additions & 8 deletions core/ajax/config.ajax.php
Expand Up @@ -19,13 +19,13 @@
try {
require_once __DIR__ . '/../../core/php/core.inc.php';
include_file('core', 'authentification', 'php');

if (!isConnect()) {
throw new Exception(__('401 - Accès non autorisé', __FILE__), -1234);
}
ajax::init();

ajax::init(array('uploadImage'));

if (init('action') == 'genApiKey') {
if (!isConnect('admin')) {
throw new Exception(__('401 - Accès non autorisé', __FILE__));
Expand All @@ -45,7 +45,7 @@
ajax::success(config::byKey('api', init('plugin')));
}
}

if (init('action') == 'getKey') {
$keys = init('key');
if ($keys == '') {
Expand All @@ -66,7 +66,7 @@
ajax::success($return);
}
}

if (init('action') == 'addKey') {
if (!isConnect('admin')) {
throw new Exception(__('401 - Accès non autorisé', __FILE__));
Expand All @@ -78,7 +78,7 @@
}
ajax::success();
}

if (init('action') == 'removeKey') {
unautorizedInDemo();
$keys = init('key');
Expand All @@ -96,7 +96,59 @@
}
ajax::success();
}


if (init('action') == 'uploadImage') {
if (!isConnect('admin')) {
throw new Exception(__('401 - Accès non autorisé', __FILE__));
}
unautorizedInDemo();

$page = init('id');
$key = 'interface::background::'.$page;
config::save($key, config::getDefaultConfiguration('core')['core'][$key], 'core');

if (!isset($_FILES['file'])) {
throw new Exception(__('Aucun fichier trouvé. Vérifiez le paramètre PHP (post size limit)', __FILE__));
}
$extension = strtolower(strrchr($_FILES['file']['name'], '.'));
if (!in_array($extension, array('.jpg', '.png'))) {
throw new Exception(__('Extension du fichier non valide (autorisé .jpg .png) : ', __FILE__) . $extension);
}
if (filesize($_FILES['file']['tmp_name']) > 5000000) {
throw new Exception(__('Le fichier est trop gros (maximum 5Mo)', __FILE__));
}

$uploaddir = realpath(__DIR__ . '/../../data/backgrounds');
if (!file_exists($uploaddir)) {
mkdir($uploaddir, 0777);
}


$filepath = $uploaddir.'/config_'.$page.$extension;
@unlink($filepath);
file_put_contents($filepath, file_get_contents($_FILES['file']['tmp_name']));
if (!file_exists($filepath)) {
throw new \Exception(__('Impossible de sauvegarder l\'image', __FILE__));
}

config::save($key, '/data/backgrounds/config_'.$page.$extension);
ajax::success();
}

if (init('action') == 'removeImage') {
if (!isConnect('admin')) {
throw new Exception(__('401 - Accès non autorisé', __FILE__));
}
unautorizedInDemo();

$page = init('id');
$key = 'interface::background::'.$page;
$filepath = config::byKey($key, 'core');
@unlink($filepath);
config::save($key, config::getDefaultConfiguration('core')['core'][$key], 'core');
ajax::success();
}

throw new Exception(__('Aucune méthode correspondante à : ', __FILE__) . init('action'));
/* * *********Catch exeption*************** */
} catch (Exception $e) {
Expand Down
13 changes: 9 additions & 4 deletions core/class/jeedom.class.php
Expand Up @@ -74,7 +74,12 @@ public static function getThemeConfig(){
'objectBackgroundBlur',
'theme_displayAsTable',
'interface::toast::position',
'interface::toast::duration'
'interface::toast::duration',
'interface::background::dashboard',
'interface::background::analysis',
'interface::background::tools',
'interface::background::opacitylight',
'interface::background::opacitydark'
);

$return = config::byKeys($key);
Expand Down Expand Up @@ -107,17 +112,17 @@ public static function getThemeConfig(){
switch ($key) {
case '--border-radius':
if ($value == '') {
$value=0;
$value = 0;
} else if($value > 1) {
$value = 1;
}
$value.='rem';
break;
case '--objectBackgroundBlur':
if ($value == '') {
$value=0;
$value = 0;
}
$value.='px';
$value .= 'px';
break;
}
}
Expand Down
5 changes: 5 additions & 0 deletions core/config/default.config.ini
Expand Up @@ -35,6 +35,11 @@ widget::margin = 4
interface::toast::position = toast-bottom-right
interface::toast::duration = 5
interface::advance::coloredcats = 1
interface::background::dashboard = core/img/background/jeedom_abstract_01_
interface::background::analysis = core/img/background/jeedom_abstract_02_
interface::background::tools = core/img/background/jeedom_abstract_03_
interface::background::opacitylight = 0.4
interface::background::opacitydark = 0.6

;history
historyCalculTendance = 2
Expand Down
19 changes: 19 additions & 0 deletions core/js/config.class.js
Expand Up @@ -212,4 +212,23 @@ jeedom.config.remove = function (_params) {
plugin: _params.plugin || 'core'
};
$.ajax(paramsAJAX);
};

jeedom.config.removeImage = function (_params) {
var paramsRequired = ['id'];
var paramsSpecifics = {};
try {
jeedom.private.checkParamsRequired(_params || {}, paramsRequired);
} catch (e) {
(_params.error || paramsSpecifics.error || jeedom.private.default_params.error)(e);
return;
}
var params = $.extend({}, jeedom.private.default_params, paramsSpecifics, _params || {});
var paramsAJAX = jeedom.private.getParamsAJAX(params);
paramsAJAX.url = 'core/ajax/config.ajax.php';
paramsAJAX.data = {
action: 'removeImage',
id: _params.id
};
$.ajax(paramsAJAX);
};
5 changes: 5 additions & 0 deletions data/backgrounds/.htaccess
@@ -0,0 +1,5 @@
Order allow,deny
<Files ~ "\.(jpeg|png|jpg)$">
allow from all
</Files>
Deny from all
56 changes: 34 additions & 22 deletions desktop/common/js/utils.js
Expand Up @@ -16,14 +16,17 @@

"use strict"

var BACKGROUND_IMG = null
var $backForJeedom = null
$(function() {
$backForJeedom = $('#backgroundforJeedom')
$(document)
.ajaxStart(function () {
$.showLoading()
})
.ajaxStop(function () {
$.hideLoading()
})
.ajaxStart(function () {
$.showLoading()
})
.ajaxStop(function () {
$.hideLoading()
})
})

//cmd update:
Expand All @@ -33,8 +36,6 @@ var utid = 0
var planEditOption = {state:false, snap:false, grid:false, gridSize:false, highlight:true}

var isEditing = false
var BACKGROUND_IMG = null
var $backForJeedom = $('#backgroundforJeedom')

//js error in ! ui:
var JS_ERROR = []
Expand Down Expand Up @@ -145,9 +146,9 @@ function loadPage(_url, _noPushHistory) {
initPage()
$('body').attr('data-page', getUrlVars('p')).trigger('jeedom_page_load')
if (BACKGROUND_IMG !== null) {
setBackgroundImg(BACKGROUND_IMG)
setBackgroundImage(BACKGROUND_IMG)
} else {
setBackgroundImg('')
setBackgroundImage('')
}
if (window.location.hash != '' && $('.nav-tabs a[href="'+window.location.hash+'"]').length != 0) {
$('.nav-tabs a[href="'+window.location.hash+'"]').click()
Expand Down Expand Up @@ -178,6 +179,9 @@ $(function() {
if (getDeviceType()['type'] == 'desktop') userDeviceType = 'desktop'
$body.attr('data-device', userDeviceType)

document.body.style.setProperty('--bkg-opacity-light', jeedom.theme['interface::background::opacitylight'])
document.body.style.setProperty('--bkg-opacity-dark', jeedom.theme['interface::background::opacitydark'])

$.alertTrigger = function() {
initRowOverflow()
}
Expand Down Expand Up @@ -253,9 +257,9 @@ $(function() {

initPage()
if (BACKGROUND_IMG != null) {
setBackgroundImg(BACKGROUND_IMG)
setBackgroundImage(BACKGROUND_IMG)
} else {
setBackgroundImg('')
setBackgroundImage('')
}

//options for notify()
Expand Down Expand Up @@ -321,7 +325,7 @@ function setJeedomTheme() {
$('#bootstrap_theme_css').attr('href', theme)
$('#bt_switchTheme').html(themeButton)
if ($("#shadows_theme_css").length > 0) $('#shadows_theme_css').attr('href', themeShadows)
setBackgroundImg(BACKGROUND_IMG)
setBackgroundImage(BACKGROUND_IMG)
triggerThemechange()
})

Expand Down Expand Up @@ -377,7 +381,7 @@ function checkThemechange() {
$('#bootstrap_theme_css').attr('href', themeCss)
$('body').attr('data-theme',theme)
if ($("#shadows_theme_css").length > 0) $('#shadows_theme_css').attr('href', 'core/themes/'+theme+'/desktop/shadows.css')
setBackgroundImg(BACKGROUND_IMG)
setBackgroundImage(BACKGROUND_IMG)
triggerThemechange()
})
.fail(function() {
Expand Down Expand Up @@ -407,7 +411,7 @@ function triggerThemechange() {
}
}

function setBackgroundImg(_path) {
function setBackgroundImage(_path) {
if (!isset(jeedom) || !isset(jeedom.theme) || !isset(jeedom.theme.showBackgroundImg) || jeedom.theme.showBackgroundImg == 0) {
return
}
Expand All @@ -420,17 +424,25 @@ function setBackgroundImg(_path) {
if ($('body').attr('data-theme') == 'core2019_Dark') {
mode = 'dark'
}
_path = 'core/img/background/jeedom_abstract_01_'+mode+'.jpg'
if (['administration','profils'].indexOf($('body').attr('data-page')) != -1) {
_path = 'core/img/background/jeedom_abstract_03_'+mode+'.jpg'

var dataPage = $('body').attr('data-page')
if (['display', 'eqAnalyse', 'log', 'timeline', 'history', 'report', 'health'].indexOf(dataPage) != -1) {
_path = jeedom.theme['interface::background::analysis']
} else if (['object', 'scenario', 'interact', 'widgets', 'plugin', 'administration', 'profils'].indexOf(dataPage) != -1) {
_path = jeedom.theme['interface::background::tools']
} else {
_path = jeedom.theme['interface::background::dashboard']
}
if (['display','eqAnalyse','log','history','report','health'].indexOf($('body').attr('data-page')) != -1) {
_path = 'core/img/background/jeedom_abstract_02_'+mode+'.jpg'

if (_path.substring(0,4) == 'core') {
$backForJeedom.removeClass('custom')
_path += mode + '.jpg'
} else {
$backForJeedom.addClass('custom')
}
$backForJeedom.css('background-image','url("'+_path+'")')

document.body.style.setProperty('--dashBkg-url','url("../../../../'+_path+'")')
} else {
$backForJeedom.css('background-image','url("'+_path+'")')
document.body.style.setProperty('--dashBkg-url','url("../../../../'+_path+'")')
}
}
Expand Down
9 changes: 7 additions & 2 deletions desktop/css/desktop.main.css
Expand Up @@ -104,17 +104,22 @@
z-index: -1;
position: fixed;
opacity: 0.4;
opacity: var(--bkg-opacity-light);
background-size: cover !important;
background-position: right bottom !important;
background-repeat: no-repeat;
background-image: var(--dashBkg-url) !important;
background-color: transparent !important;
}
#backgroundforJeedom.custom {
background-position: center !important;
}
[data-page="dashboard"] #backgroundforJeedom {
filter: blur(var(--objectBackgroundBlur));
}
[data-theme*="Dark"] #backgroundforJeedom {
opacity : 0.6;
opacity: 0.6;
opacity: var(--bkg-opacity-dark);
}

#dashTopBar {
Expand Down Expand Up @@ -676,7 +681,7 @@
body[data-coloredcats="0"] div.eqLogic-widget .widget-name,
body[data-coloredcats="0"] div.scenario.scenario-widget .widget-name {
background: transparent !important;
border-bottom: 1px solid var(--el-defaultColor) !important;
border-bottom: 1px solid rgba(var(--bg-color), var(--opacity)) !important;
}
body[data-coloredcats="0"] div.eqLogic-widget .widget-name > .reportModeHidden,
body[data-coloredcats="0"] div.scenario.scenario-widget .widget-name > a,
Expand Down
34 changes: 34 additions & 0 deletions desktop/js/administration.js
Expand Up @@ -266,6 +266,40 @@ $divConfig.off('change','.configKey').on('change','.configKey:visible', functio
setCookie('currentTheme', '', -1)
})

$('.bt_uploadImage').each(function() {
$(this).fileupload({
replaceFileInput: false,
url: 'core/ajax/config.ajax.php?action=uploadImage&id=' + $(this).attr('data-page'),
dataType: 'json',
done: function(e, data) {
if (data.result.state != 'ok') {
$('#div_alert').showAlert({message: data.result.result, level: 'danger'})
return
}
$('#div_alert').showAlert({message: '{{Image enregistrée et configurée}}', level: 'success'})
}
})
})

$divConfig.on({
'click': function(event) {
var dataPage = $(this).attr('data-page')
bootbox.confirm('{{Êtes-vous sûr de vouloir supprimer cette image de fond ?}}', function(result) {
if (result) {
jeedom.config.removeImage({
id: dataPage,
error: function(error) {
$('#div_alert').showAlert({message: error.message, level: 'danger'})
},
success: function() {
$('#div_alert').showAlert({message: '{{Image supprimée}}', level: 'success'})
},
})
}
})
}
}, '.bt_removeBackgroundImage')

/**************************NETWORK***********************************/
$divConfig.on({
'change': function(event) {
Expand Down

0 comments on commit 258c227

Please sign in to comment.