Skip to content

Commit

Permalink
ncp-web: collapse sidebar menu when clicking in new sections
Browse files Browse the repository at this point in the history
  • Loading branch information
nachoparker committed Apr 5, 2018
1 parent 6031440 commit eece4d0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 158 deletions.
2 changes: 1 addition & 1 deletion ncp-web/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
echo <<<HTML
<div id="first-run-wizard">
<div class='dialog'>
<br>
<br><br>
<h2 id="config-box-title">NextCloudPi First Run</h2>
<p>Click to start the configuration wizard</p>
<br>
Expand Down
6 changes: 6 additions & 0 deletions ncp-web/ncp.css
Original file line number Diff line number Diff line change
Expand Up @@ -1193,11 +1193,17 @@ a#versionlink:hover {
cursor:pointer;
}

#first-run-wizard img {
width: 70%;
max-width: 210px;
}

.dialog {
display:block;
background: white;
position:relative;
width:50%;
max-width: 400px;
top:25%;
margin:0px auto;
}
Expand Down
81 changes: 44 additions & 37 deletions ncp-web/ncp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
var MINI = require('minified');
var $ = MINI.$, $$ = MINI.$$, EE = MINI.EE;
var selectedID = null;
var confLock = false;
var lock = false;

function errorMsg()
{
Expand All @@ -27,8 +27,12 @@ function switch_to_section( name )
selectedID = null;
}

// slide menu
var slide_menu_enabled = false;

function open_menu()
{
if ( !slide_menu_enabled ) return;
if ( $('#app-navigation').get('$width') != '250px' )
{
$('#overlay').show();
Expand All @@ -39,6 +43,7 @@ function open_menu()

function close_menu()
{
if ( !slide_menu_enabled ) return;
if ( $('#app-navigation').get('$width') == '250px' )
{
$('#app-navigation').animate( {$width: '0px'}, 150 );
Expand All @@ -47,6 +52,32 @@ function close_menu()
}
}

function hide_overlay(e) { $('#overlay').hide() }

function close_menu_on_click_out(e) { close_menu(); }

function enable_slide_menu()
{
if ( slide_menu_enabled ) return;
$( '#app-navigation' ).set( { $width: '0px' } );
$( '#app-navigation' ).set( { $position: 'absolute' } );
$( '#app-navigation-toggle' ).on('click', open_menu );
$( '#app-content' ).on('|click', close_menu_on_click_out );
slide_menu_enabled = true;
}

function disable_slide_menu()
{
if ( !slide_menu_enabled ) return;
$.off( open_menu );
$.off( close_menu );
$.off( close_menu_on_click_out );
$( '#app-navigation' ).set( { $width: '250px' } );
$( '#app-navigation' ).set( { $position: 'unset' } );
$('#overlay').hide();
slide_menu_enabled = false;
}

function set_sidebar_click_handlers()
{
// Show selected option configuration box
Expand All @@ -55,8 +86,8 @@ function set_sidebar_click_handlers()
if ( selectedID == this.get( '.id' ) ) // already selected
return;

if ( confLock ) return;
confLock = true;
if ( lock ) return;
lock = true;

if ( window.innerWidth <= 768 )
close_menu();
Expand All @@ -69,7 +100,7 @@ function set_sidebar_click_handlers()
function success( result )
{
cfgreqReceive( result, that );
confLock = false;
lock = false;
}).error( errorMsg );
});
}
Expand Down Expand Up @@ -138,7 +169,7 @@ $(function()
// Launch selected script
$( '#config-button' ).on('click', function(e)
{
confLock = true;
lock = true;
$('#details-box').hide( '' );
$('#config-button').set('@disabled',true);
$('#loading-gif').set( { $display: 'inline' } );
Expand Down Expand Up @@ -201,15 +232,15 @@ $(function()
$( 'input' , '#config-box-wrapper' ).set('@disabled', null);
$('#config-button').set('@disabled',null);
$('#loading-gif').hide();
confLock = false;
lock = false;
}).error( errorMsg );
});

// Update notification
$( '#notification' ).on('click', function(e)
{
if ( confLock ) return;
confLock = true;
if ( lock ) return;
lock = true;

$( '#' + selectedID ).set('-active');

Expand All @@ -220,7 +251,7 @@ $(function()
function success( result )
{
cfgreqReceive( result, $( '#nc-update' ) );
confLock = false;
lock = false;
}
).error( errorMsg );

Expand All @@ -229,34 +260,6 @@ $(function()
} );

// slide menu
var slide_menu_enabled = false;

function hide_overlay(e) { $('#overlay').hide() }

function close_menu_on_click_out(e) { close_menu(); }

function enable_slide_menu()
{
if ( slide_menu_enabled ) return;
$( '#app-navigation' ).set( { $width: '0px' } );
$( '#app-navigation' ).set( { $position: 'absolute' } );
$( '#app-navigation-toggle' ).on('click', open_menu );
$( '#app-content' ).on('|click', close_menu_on_click_out );
slide_menu_enabled = true;
}

function disable_slide_menu()
{
if ( !slide_menu_enabled ) return;
$.off( open_menu );
$.off( close_menu );
$.off( close_menu_on_click_out );
$( '#app-navigation' ).set( { $width: '250px' } );
$( '#app-navigation' ).set( { $position: 'unset' } );
$('#overlay').hide();
slide_menu_enabled = false;
}

if ( window.innerWidth <= 768 )
enable_slide_menu();

Expand Down Expand Up @@ -350,12 +353,16 @@ $(function()
// dashboard button
$( '#dashboard-btn' ).on('click', function(e)
{
if ( lock ) return;
close_menu();
switch_to_section( 'dashboard' );
} );

// config button
$( '#config-btn' ).on('click', function(e)
{
if ( lock ) return;
close_menu();
switch_to_section( 'nc-config' );
} );
} );
Expand Down
1 change: 1 addition & 0 deletions ncp-web/wizard/CSS/wizard.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ a:hover, a:active, a:link {
.ncp-tab-pane {
display: table;
margin: 0 auto;
text-align: center;
}
.ncp-tab-pane p {
text-align: center;
Expand Down
120 changes: 0 additions & 120 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,103 +121,6 @@ done
# not for image builds, only live updates
[[ ! -f /.ncp-image ]] && {

# update ncp-backup
cd "$CONFDIR" &>/dev/null
install_script nc-backup.sh &>/dev/null
cd - &>/dev/null

# randomize passwords for old images ( older than v0.46.30 )
cat > /usr/lib/systemd/system/nc-provisioning.service <<'EOF'
[Unit]
Description=Randomize passwords on first boot
Requires=network.target
After=mysql.service
[Service]
ExecStart=/bin/bash /usr/local/bin/ncp-provisioning.sh
[Install]
WantedBy=multi-user.target
EOF
systemctl enable nc-provisioning

NEED_UPDATE=false

MAJOR=0 MINOR=46 PATCH=30

MAJ=$( grep -oP "\d+\.\d+\.\d+" /usr/local/etc/ncp-version | cut -d. -f1 )
MIN=$( grep -oP "\d+\.\d+\.\d+" /usr/local/etc/ncp-version | cut -d. -f2 )
PAT=$( grep -oP "\d+\.\d+\.\d+" /usr/local/etc/ncp-version | cut -d. -f3 )

if [ "$MAJOR" -gt "$MAJ" ]; then
NEED_UPDATE=true
elif [ "$MAJOR" -eq "$MAJ" ] && [ "$MINOR" -gt "$MIN" ]; then
NEED_UPDATE=true
elif [ "$MAJOR" -eq "$MAJ" ] && [ "$MINOR" -eq "$MIN" ] && [ "$PATCH" -gt "$PAT" ]; then
NEED_UPDATE=true
fi

[[ "$NEED_UPDATE" == "true" ]] && {
REDISPASS="default"
DBPASSWD="default"
sed -i -E "s|^requirepass .*|requirepass $REDISPASS|" /etc/redis/redis.conf
echo -e "[client]\npassword=$DBPASSWD" > /root/.my.cnf
chmod 600 /root/.my.cnf
systemctl start nc-provisioning
}

# adjust services
systemctl mask nfs-blkmap
grep -q '^ACTIVE_=yes$' "$CONFDIR"/samba.sh || update-rc.d nmbd disable

# fix automount dependencies with other ncp-apps
sed -i \
's|^Before=.*|Before=mysqld.service dphys-swapfile.service fail2ban.service smbd.service nfs-server.service|' \
/usr/lib/systemd/system/nc-automount.service

sed -i \
's|^Before=.*|Before=nc-automount.service|' \
/usr/lib/systemd/system/nc-automount-links.service

# adjust when other services start
DBUNIT=/lib/systemd/system/mariadb.service
F2BUNIT=/lib/systemd/system/fail2ban.service
SWPUNIT=/etc/init.d/dphys-swapfile
grep -q sleep "$DBUNIT" || sed -i "/^ExecStart=/iExecStartPre=/bin/sleep 10" "$DBUNIT"
grep -q sleep "$F2BUNIT" || sed -i "/^ExecStart=/iExecStartPre=/bin/sleep 10" "$F2BUNIT"
grep -q sleep "$SWPUNIT" || sed -i "/\<start)/asleep 30" "$SWPUNIT"

# disable ncp user login
chsh -s /usr/sbin/nologin ncp

# remove old instance of ramlogs
[[ -f /usr/lib/systemd/system/ramlogs.service ]] && {
systemctl disable ramlogs
rm -f /usr/lib/systemd/system/ramlogs.service /usr/local/bin/ramlog-dirs.sh
}
sed -i '/tmpfs \/var\/log.* in RAM$/d' /etc/fstab
sed -i '/tmpfs \/tmp.* in RAM$/d' /etc/fstab

# update ramlogs with log2ram
type log2ram &>/dev/null || {
cd "$CONFDIR" &>/dev/null
install_script nc-ramlogs.sh &>/dev/null
grep -q '^ACTIVE_=yes$' "$CONFDIR"/nc-ramlogs.sh && \
systemctl enable log2ram
cd - &>/dev/null
}

# update nc-backup-auto to use cron
[[ -f /etc/systemd/system/nc-backup.timer ]] && {
systemctl stop nc-backup.timer
systemctl disable nc-backup.timer
rm -f /etc/systemd/system/nc-backup.timer /etc/systemd/system/nc-backup.service
cd "$CONFDIR" &>/dev/null
grep -q '^ACTIVE_=yes$' "$CONFDIR"/nc-backup-auto.sh && \
activate_script nc-backup-auto.sh
cd - &>/dev/null
}

# make sure the redis directory exists
mkdir -p /var/log/redis
chown redis /var/log/redis
Expand Down Expand Up @@ -271,29 +174,6 @@ EOF
systemctl stop log2ram
}

# add new virtual host for initial password setup
cat > /etc/apache2/sites-available/ncp-activation.conf <<EOF
<VirtualHost _default_:443>
DocumentRoot /var/www/ncp-web/
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
</VirtualHost>
<Directory /var/www/ncp-web/>
<RequireAll>
<RequireAny>
Require host localhost
Require local
Require ip 192.168
Require ip 172
Require ip 10
</RequireAny>
</RequireAll>
</Directory>
EOF
} # end - only live updates

exit 0
Expand Down

0 comments on commit eece4d0

Please sign in to comment.