Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

191 final config yaml is missing settings section #216

Merged
merged 3 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,12 @@ def step(name):

print(f"data retrieved for {name}")

page_info["plex_valid"], page_info["tmdb_valid"], page_info["libs_valid"] = (
check_minimum_settings()
)
(
page_info["plex_valid"],
page_info["tmdb_valid"],
page_info["libs_valid"],
page_info["sett_valid"],
) = check_minimum_settings()

page_info["notifiarr_available"], page_info["gotify_available"] = (
notification_systems_available()
Expand Down
3 changes: 2 additions & 1 deletion modules/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ def check_minimum_settings():
plex_valid, plex_user_entered = retrieve_status("plex")
tmdb_valid, tmdb_user_entered = retrieve_status("tmdb")
libs_valid, libs_user_entered = retrieve_status("libraries")
sett_valid, sett_user_entered = retrieve_status("settings")

return plex_valid, tmdb_valid, libs_valid
return plex_valid, tmdb_valid, libs_valid, sett_valid


def flush_session_storage(name):
Expand Down
111 changes: 48 additions & 63 deletions static/local-js/150-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,40 @@
document.addEventListener('DOMContentLoaded', function () {
const saveSyncChangesButton = document.getElementById('saveSyncChangesButton')
const saveExcludeChangesButton = document.getElementById('saveExcludeChangesButton')
const validateSettingsButton = document.getElementById('validateSettingsButton')
const validationMessages = $('#validation-messages')

function showValidationMessage (type, message) {
validationMessages
.removeClass('alert-success alert-danger')
.addClass(type === 'success' ? 'alert-success' : 'alert-danger')
.html(message)
.show()
const configForm = document.getElementById('configForm')

function setSettingsValidated (isValid) {
const settingsValidatedInput = document.getElementById('settings_validated')
settingsValidatedInput.value = isValid ? 'true' : 'false'
}

function submitFormData () {
if (configForm.checkValidity()) {
const formData = new FormData(configForm)
fetch(configForm.action, {
method: 'POST',
body: formData
})
.then((response) => {
if (response.ok) {
console.log('Settings saved successfully.')
} else {
console.error('Error saving settings:', response.statusText)
}
})
.catch((error) => {
console.error('Error saving settings:', error)
})
} else {
console.warn('Form validation failed. Data not saved.')
}
}

setSettingsValidated(true)

saveSyncChangesButton.addEventListener('click', function () {
const selectedUsers = []
const checkboxes = document.querySelectorAll('#syncUserListForm input[type="checkbox"]:checked')

const allSelected = document.getElementById('sync_all_users').checked

if (allSelected) {
Expand All @@ -33,7 +52,7 @@ document.addEventListener('DOMContentLoaded', function () {
const csvUsers = selectedUsers.join(', ')
document.getElementById('playlist_sync_to_users').value = csvUsers
$('#syncUsersModal').modal('hide')
setSettingsValidated(false)
setSettingsValidated(true)
})

saveExcludeChangesButton.addEventListener('click', function () {
Expand All @@ -47,25 +66,9 @@ document.addEventListener('DOMContentLoaded', function () {
const csvUsers = selectedUsers.join(', ')
document.getElementById('playlist_exclude_users').value = csvUsers
$('#excludeUsersModal').modal('hide')
setSettingsValidated(false)
setSettingsValidated(true)
})

validateSettingsButton.addEventListener('click', function () {
if (validateForm()) {
setSettingsValidated(true)
this.disabled = true
showValidationMessage('success', 'Settings validated successfully!')
} else {
showValidationMessage('danger', 'Please correct the errors in the form.')
}
})

function setSettingsValidated (isValid) {
const settingsValidatedInput = document.getElementById('settings_validated')
settingsValidatedInput.value = isValid ? 'true' : 'false'
validateSettingsButton.disabled = isValid
}

const syncAllUsersCheckbox = document.getElementById('sync_all_users')
syncAllUsersCheckbox.addEventListener('change', function () {
if (this.checked) {
Expand All @@ -74,7 +77,7 @@ document.addEventListener('DOMContentLoaded', function () {
checkbox.checked = false
})
}
setSettingsValidated(false)
setSettingsValidated(true)
})

const syncUserCheckboxes = document.querySelectorAll('#syncUserListForm input[type="checkbox"]:not(#sync_all_users)')
Expand All @@ -83,49 +86,37 @@ document.addEventListener('DOMContentLoaded', function () {
if (this.checked) {
syncAllUsersCheckbox.checked = false
}
setSettingsValidated(false)
setSettingsValidated(true)
})
})

// Add change event listeners to all inputs and selects to detect changes
document.querySelectorAll('input, select, textarea').forEach(element => {
document.querySelectorAll('input, select, textarea').forEach((element) => {
element.addEventListener('change', function () {
setSettingsValidated(false)
setSettingsValidated(true)
})
})

document.querySelectorAll('button[onclick], .dropdown-menu a').forEach((element) => {
element.addEventListener('click', function () {
submitFormData()
})
})
})

$(document).ready(function () {
const isValidated = document.getElementById('settings_validated').value.toLowerCase()
console.log('Validated: ' + isValidated)

if (isValidated === 'true') {
document.getElementById('validateSettingsButton').disabled = true
} else {
document.getElementById('validateSettingsButton').disabled = false
}
})

function validatePath (input) {
// Regular expression for validating paths
// Accepts paths like:
// Windows absolute: C:\Folder\file.txt, \\server\share\file.txt
// Windows relative: folder\subfolder\file.txt
// Unix absolute: /path/to/file.txt
// Unix relative: ./relative/path/file.txt, config/assets
const pathRegex = /^(?:[a-zA-Z]:\\(?:[^\\/:*?"<>|\r\n]+\\)*[^\\/:*?"<>|\r\n]*|\\{2}[^\\/:*?"<>|\r\n]+(?:\\[^\\/:*?"<>|\r\n]+)*|(?:[^\\/:*?"<>|\r\n]+\\)*[^\\/:*?"<>|\r\n]+|\/(?:[^\/]+\/)*[^\/]*|\.{1,2}(?:\/[^\/]*)*|(?:[^\/]+\/)*[^\/]*)$/ // eslint-disable-line
const pathRegex = /^(?:[a-zA-Z]:\\(?:[^\\/:*?"<>|\r\n]+\\)*[^\\/:*?"<>|\r\n]*|\\{2}[^\\/:*?"<>|\r\n]+(?:\\[^\\/:*?"<>|\r\n]+)*|(?:[^\\/:*?"<>|\r\n]+\\)*[^\\/:*?"<>|\r\n]+|\/(?:[^\/]+\/)*[^\/]*|\.{1,2}(?:\/[^\/]*)*|(?:[^\/]+\/)*[^\/]*)$/ // eslint-disable-line
return pathRegex.test(input)
}

function validateCSVList (input) {
// If the input is null or empty, return true (consider it valid)
if (!input) {
return true
}

// Regular expression for validating CSV lists
// Accepts lists like: item1, item2, item3
// Each item can be alphanumeric and can include spaces, hyphens, underscores, and dots
const csvRegex = /^(\s*[a-zA-Z0-9-_.]+\s*)(,\s*[a-zA-Z0-9-_.]+\s*)*$/
return csvRegex.test(input)
}
Expand Down Expand Up @@ -158,43 +149,37 @@ function validateURL (input) {
function validateForm () {
const assetDirectoryInput = document.getElementById('asset_directory').value.trim()

// Check if assetDirectoryInput is null or empty
if (!assetDirectoryInput || assetDirectoryInput.toLowerCase() === 'none' || !validatePath(assetDirectoryInput)) {
alert('Please enter a valid asset directory path.')
return false // Prevent form submission
return false
}

// Validate CSV list fields
const csvFields = ['playlist_sync_to_users', 'playlist_exclude_users']
for (const fieldId of csvFields) {
const fieldValue = document.getElementById(fieldId).value.trim()
if (!validateCSVList(fieldValue)) {
alert(`Please enter a valid CSV list for ${fieldId.replace('_', ' ')}.`)
return false // Prevent form submission
return false
}
}

// Validate ignore_ids to be numeric
const ignoreIds = document.getElementById('ignore_ids').value.trim()
if (ignoreIds && ignoreIds.toLower !== 'none' && !validateNumericCSV(ignoreIds)) {
alert('Please enter a valid CSV list of numeric IDs for ignore_ids.')
return false // Prevent form submission
return false
}

// Validate ignore_imdb_ids to start with tt followed by numbers
const ignoreImdbIds = document.getElementById('ignore_imdb_ids').value.trim()
if (ignoreImdbIds && ignoreImdbIds.toLower !== 'none' && !validateIMDBCSV(ignoreImdbIds)) {
alert('Please enter a valid CSV list of IMDb IDs for ignore_imdb_ids (starting with tt followed by at least 7 digits).')
return false // Prevent form submission
return false
}

// Validate custom_repo to be a valid URL
const customRepo = document.getElementById('custom_repo').value.trim()
if (customRepo && customRepo.toLower !== 'none' && !validateURL(customRepo)) {
alert('Please enter a valid URL for custom_repo.')
return false // Prevent form submission
return false
}

// Additional form validation logic can go here if needed
return true // Allow form submission
return true
}
10 changes: 9 additions & 1 deletion static/local-js/900-final.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ $(document).ready(function () {
const plexValid = $('#plex_valid').data('plex-valid') === 'True'
const tmdbValid = $('#tmdb_valid').data('tmdb-valid') === 'True'
const libsValid = $('#libs_valid').data('libs-valid') === 'True'
const settValid = $('#sett_valid').data('sett-valid') === 'True'
const yamlValid = $('#yaml_valid').data('yaml-valid') === 'True'
// const validationError = $('#validation-error').val().trim()
// Debugging: Check the values of the meta tags

const showYAML = plexValid && tmdbValid && libsValid && yamlValid
const showYAML = plexValid && tmdbValid && libsValid && settValid && yamlValid

console.log('Plex Valid:', plexValid)
console.log('TMDb Valid:', tmdbValid)
console.log('LIBS Valid:', libsValid)
console.log('Settings Valid:', settValid)
console.log('YAML Valid:', yamlValid)
console.log('Show YAML:', showYAML)

Expand All @@ -40,6 +42,12 @@ $(document).ready(function () {
)
}

if (!settValid) {
validationMessages.push(
'Settings page values have likely been skipped. Please <a href="javascript:void(0);" onclick="jumpTo(\'150-settings\');">return to the Settings page</a> and ensure you make appropriate selections before returning here.<br>'
)
}

// If there are validation messages, display them
if (!showYAML) {
if (validationMessages.length > 0) {
Expand Down
1 change: 1 addition & 0 deletions templates/000-base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta id="plex_valid" data-plex-valid="{{ page_info['plex_valid'] }}">
<meta id="tmdb_valid" data-tmdb-valid="{{ page_info['tmdb_valid'] }}">
<meta id="libs_valid" data-libs-valid="{{ page_info['libs_valid'] }}">
<meta id="sett_valid" data-sett-valid="{{ page_info['sett_valid'] }}">
<meta id="yaml_valid" data-yaml-valid="{{ page_info['yaml_valid'] }}">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>{{ page_info['title'] }} - Kometa YAML Config Wizard</title>
Expand Down
4 changes: 0 additions & 4 deletions templates/150-settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -533,10 +533,6 @@ <h2 class="accordion-header">
</div>
<div id="statusMessage" class="status-message"></div>
<br>
<!-- Validate Button -->
<div class="text-center">
<button type="button" class="btn btn-primary" id="validateSettingsButton">Validate</button>
</div>
</div>
</form>
{% endblock %}
18 changes: 0 additions & 18 deletions templates/900-final.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,5 @@ <h5>These error(s) occurred while validating your config:</h5><br>
<a href="{{ url_for('download') }}" id="download-btn" class="btn btn-success d-none">Download Config</a>
<a href="{{ url_for('download_redacted') }}" id="download-redacted-btn" class="btn btn-warning d-none">Download Redacted Config</a>
{% endif %}
<div class="form-floating">
<div class="form-text">
<br><h5>Here is an example of what the Collections might look like.</h5><br>
</div>
</div>
<div class="text-center"></div>
<div>
<img src="https://kometa.wiki/en/latest/kometa/install/images/wt-default-collections.png" alt="Kometa Default Collections" class="img-fluid">
</div>
<div class="form-floating">
<div class="form-text">
<br><h5>Here is an example of what the Ribbon Overlays might look like.</h5><br>
</div>
</div>
<div class="text-center"></div>
<div>
<img src="https://kometa.wiki/en/latest/defaults/overlays/images/ribbon.png" alt="Kometa Ribbon" class="img-fluid">
</div>
</form>
{% endblock %}
7 changes: 3 additions & 4 deletions templates/modals/150-settings.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<div class="alert alert-info" role="alert">
<h6><b>This section is optional</b></h6>
Go through each section and change any settings you need to and press "Validate".
<br>Alternatively, press the green arrow button to skip ahead.
<div class="alert alert-danger" role="alert">
<h6><b>This section is mandatory</b></h6>
Go through each section and change any settings you need to.
<br><br><a href="https://kometa.wiki/en/latest/config/settings/" target="_blank">Click Here</a> to go to the Kometa wiki for the Settings attributes.
</div>
Loading