removed update system, added delete file

This commit is contained in:
Ross Mountjoy 2020-02-01 19:20:18 -05:00
parent 55ffaaf13d
commit 52fda77c65
6 changed files with 41 additions and 92 deletions

View File

@ -1,8 +1,9 @@
import os import os
import subprocess
from shutil import copyfile from shutil import copyfile
from requests import get from requests import get
from configparser import ConfigParser from configparser import ConfigParser
from dashmachine.paths import dashmachine_folder, images_folder from dashmachine.paths import dashmachine_folder, images_folder, root_folder
from dashmachine.main.models import Apps, ApiCalls, TemplateApps from dashmachine.main.models import Apps, ApiCalls, TemplateApps
from dashmachine.settings_system.models import Settings from dashmachine.settings_system.models import Settings
from dashmachine.user_system.models import User from dashmachine.user_system.models import User
@ -164,6 +165,12 @@ def public_route(decorated_function):
def dashmachine_init(): def dashmachine_init():
migrate_cmd = "python " + os.path.join(root_folder, "manage_db.py db migrate")
subprocess.run(migrate_cmd, stderr=subprocess.PIPE, shell=True, encoding="utf-8")
upgrade_cmd = "python " + os.path.join(root_folder, "manage_db.py db upgrade")
subprocess.run(upgrade_cmd, stderr=subprocess.PIPE, shell=True, encoding="utf-8")
read_config() read_config()
read_template_apps() read_template_apps()
user_data_folder = os.path.join(dashmachine_folder, "user_data") user_data_folder = os.path.join(dashmachine_folder, "user_data")

View File

@ -7,7 +7,6 @@ from dashmachine.user_system.utils import add_edit_user
from dashmachine.main.utils import read_config, row2dict from dashmachine.main.utils import read_config, row2dict
from dashmachine.main.models import Files, TemplateApps from dashmachine.main.models import Files, TemplateApps
from dashmachine.paths import backgrounds_images_folder, icons_images_folder from dashmachine.paths import backgrounds_images_folder, icons_images_folder
from dashmachine.update import check_needed, update_dashmachine
from dashmachine.version import version from dashmachine.version import version
from dashmachine.settings_system.utils import load_files_html from dashmachine.settings_system.utils import load_files_html
@ -56,6 +55,16 @@ def add_images():
return load_files_html() return load_files_html()
@settings_system.route("/settings/delete_file", methods=["GET"])
def delete_file():
if request.args.get("folder") == "backgrounds":
file = os.path.join(backgrounds_images_folder, request.args.get("file"))
if request.args.get("folder") == "icons":
file = os.path.join(icons_images_folder, request.args.get("file"))
os.remove(file)
return load_files_html()
@settings_system.route("/settings/get_app_template", methods=["GET"]) @settings_system.route("/settings/get_app_template", methods=["GET"])
def get_app_template(): def get_app_template():
template_app = TemplateApps.query.filter_by(name=request.args.get("name")).first() template_app = TemplateApps.query.filter_by(name=request.args.get("name")).first()
@ -66,17 +75,6 @@ def get_app_template():
return template return template
@settings_system.route("/settings/update", methods=["GET"])
def update():
update_dashmachine()
return "ok"
@settings_system.route("/settings/check_update", methods=["GET"])
def check_update():
return str(check_needed())
@settings_system.route("/settings/edit_user", methods=["POST"]) @settings_system.route("/settings/edit_user", methods=["POST"])
def edit_user(): def edit_user():
form = UserForm() form = UserForm()

View File

@ -58,33 +58,6 @@ $( document ).ready(function() {
} }
}); });
$("#update-btn").on('click', function(e) {
$.ajax({
url: $(this).attr('data-url'),
type: 'GET',
success: function(data){
M.toast({html: 'DashMachine Updated'});
$("#update-btn").addClass('hide');
$("#check-update-btn").removeClass('hide');
}
});
});
$("#check-update-btn").on('click', function(e) {
$.ajax({
url: $(this).attr('data-url'),
type: 'GET',
success: function(data){
if (data === "True"){
$("#update-btn").removeClass('hide');
$("#check-update-btn").addClass('hide');
} else {
M.toast({html: 'Up to date!'});
}
}
});
});
$("#edit-user-btn").on('click', function(e) { $("#edit-user-btn").on('click', function(e) {
$.ajax({ $.ajax({
url: $(this).attr('data-url'), url: $(this).attr('data-url'),

View File

@ -17,7 +17,12 @@
<img src="static/images/backgrounds/{{ background }}" alt="" class="circle"> <img src="static/images/backgrounds/{{ background }}" alt="" class="circle">
</a> </a>
<span class="selectable-all copy-target file-title">static/images/backgrounds/{{ background }}</span> <span class="selectable-all copy-target file-title">static/images/backgrounds/{{ background }}</span>
<span class="secondary-content"><i class="material-icons-outlined icon-btn">close</i></span> <span class="secondary-content">
<i class="material-icons-outlined icon-btn delete-file-btn"
data-url="{{ url_for('settings_system.delete_file') }}"
data-folder="backgrounds"
data-file="{{ background }}">close</i>
</span>
<span class="secondary-content mr-4"><i class="material-icons-outlined icon-btn copy-btn">filter_none</i></span> <span class="secondary-content mr-4"><i class="material-icons-outlined icon-btn copy-btn">filter_none</i></span>
</li> </li>
{% endfor %} {% endfor %}
@ -39,7 +44,12 @@
<img src="static/images/icons/{{ icon }}" alt="" class="circle"> <img src="static/images/icons/{{ icon }}" alt="" class="circle">
</a> </a>
<span class="selectable-all copy-target file-title">static/images/icons/{{ icon }}</span> <span class="selectable-all copy-target file-title">static/images/icons/{{ icon }}</span>
<span class="secondary-content"><i class="material-icons-outlined icon-btn">close</i></span> <span class="secondary-content">
<i class="material-icons-outlined icon-btn delete-file-btn"
data-url="{{ url_for('settings_system.delete_file') }}"
data-folder="icons"
data-file="{{ icon }}">close</i>
</span>
<span class="secondary-content mr-4"><i class="material-icons-outlined icon-btn copy-btn">filter_none</i></span> <span class="secondary-content mr-4"><i class="material-icons-outlined icon-btn copy-btn">filter_none</i></span>
</li> </li>
{% endfor %} {% endfor %}
@ -53,5 +63,16 @@
<script> <script>
$( document ).ready(function() { $( document ).ready(function() {
init_copy_btn(".collection-item"); init_copy_btn(".collection-item");
$(".delete-file-btn").on('click', function(e) {
$.ajax({
url: $(this).attr('data-url'),
type: 'GET',
data: {folder: $(this).attr("data-folder"), file: $(this).attr("data-file")},
success: function(data){
$("#files-div").empty();
$("#files-div").append(data);
}
});
});
}); });
</script> </script>

View File

@ -390,23 +390,6 @@
<h5>DashMachine</h5> <h5>DashMachine</h5>
<p class="mb-2">version: {{ version }}</p> <p class="mb-2">version: {{ version }}</p>
{{ button(
float="left",
id="update-btn",
icon="system_update_alt",
class="hide",
data={"url": url_for('settings_system.update')},
text="update available"
) }}
{{ button(
float="left",
id="check-update-btn",
icon="security",
data={"url": url_for('settings_system.check_update')},
text="check for update"
) }}
</div> </div>
</div> </div>

View File

@ -1,33 +0,0 @@
import os
import subprocess
from dashmachine.paths import root_folder
def check_needed():
subprocess.run("git remote update", shell=True)
out = subprocess.run(
"git status -uno", stdout=subprocess.PIPE, shell=True, encoding="utf-8"
)
if str(out.stdout).find("Your branch is up to date") > -1:
needed = False
return needed
elif str(out.stdout).find("Your branch is up-to-date") > -1:
needed = False
return needed
else:
needed = True
return needed
def update_dashmachine():
subprocess.run(
"git pull origin master", stdout=subprocess.PIPE, shell=True, encoding="utf-8"
)
migrate_cmd = "python " + os.path.join(root_folder, "manage_db.py db migrate")
subprocess.run(migrate_cmd, stderr=subprocess.PIPE, shell=True, encoding="utf-8")
upgrade_cmd = "python " + os.path.join(root_folder, "manage_db.py db upgrade")
subprocess.run(upgrade_cmd, stderr=subprocess.PIPE, shell=True, encoding="utf-8")