Последняя версия с сервера прошлого разработчика

This commit is contained in:
2025-07-10 04:35:51 +00:00
commit c731570032
1174 changed files with 134314 additions and 0 deletions

248
nova/resources/js/mixins/HandlesActions.js vendored Executable file
View File

@@ -0,0 +1,248 @@
import { Errors } from 'laravel-nova'
export default {
props: {
resourceName: String,
actions: {},
pivotActions: {
default: () => [],
},
endpoint: {
type: String,
default: null,
},
queryString: {
type: Object,
default: () => ({
currentSearch: '',
encodedFilters: '',
currentTrashed: '',
viaResource: '',
viaResourceId: '',
viaRelationship: '',
}),
},
},
data: () => ({
working: false,
selectedActionKey: '',
errors: new Errors(),
confirmActionModalOpened: false,
}),
methods: {
/**
* Determine whether the action should redirect or open a confirmation modal
*/
determineActionStrategy() {
if (this.selectedAction.withoutConfirmation) {
this.executeAction()
} else {
this.openConfirmationModal()
}
},
/**
* Confirm with the user that they actually want to run the selected action.
*/
openConfirmationModal() {
this.confirmActionModalOpened = true
},
/**
* Close the action confirmation modal.
*/
closeConfirmationModal() {
this.confirmActionModalOpened = false
this.errors = new Errors()
},
/**
* Close the action response modal.
*/
closeActionResponseModal() {
this.showActionResponseModal = false
},
/**
* Initialize all of the action fields to empty strings.
*/
initializeActionFields() {
_(this.allActions).each(action => {
_(action.fields).each(field => {
field.fill = () => ''
})
})
},
/**
* Execute the selected action.
*/
executeAction() {
this.working = true
Nova.request({
method: 'post',
url: this.endpoint || `/nova-api/${this.resourceName}/action`,
params: this.actionRequestQueryString,
data: this.actionFormData(),
})
.then(response => {
this.confirmActionModalOpened = false
this.handleActionResponse(response.data)
this.working = false
})
.catch(error => {
this.working = false
if (error.response.status == 422) {
this.errors = new Errors(error.response.data.errors)
Nova.error(this.__('There was a problem executing the action.'))
}
})
},
/**
* Gather the action FormData for the given action.
*/
actionFormData() {
return _.tap(new FormData(), formData => {
formData.append('resources', this.selectedResources)
_.each(this.selectedAction.fields, field => {
field.fill(formData)
})
})
},
/**
* Handle the action response. Typically either a message, download or a redirect.
*/
handleActionResponse(data) {
if (data.modal) {
this.actionResponseData = data
this.showActionResponseModal = true
} else if (data.message) {
this.$emit('actionExecuted')
Nova.$emit('action-executed')
Nova.success(data.message)
} else if (data.deleted) {
this.$emit('actionExecuted')
Nova.$emit('action-executed')
} else if (data.danger) {
this.$emit('actionExecuted')
Nova.$emit('action-executed')
Nova.error(data.danger)
} else if (data.download) {
let link = document.createElement('a')
link.href = data.download
link.download = data.name
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
} else if (data.redirect) {
window.location = data.redirect
} else if (data.push) {
this.$router.push(data.push)
} else if (data.openInNewTab) {
window.open(data.openInNewTab, '_blank')
} else {
this.$emit('actionExecuted')
Nova.$emit('action-executed')
Nova.success(this.__('The action ran successfully!'))
}
},
},
computed: {
/**
* Get the query string for an action request.
*/
actionRequestQueryString() {
return {
action: this.selectedActionKey,
pivotAction: this.selectedActionIsPivotAction,
search: this.queryString.currentSearch,
filters: this.queryString.encodedFilters,
trashed: this.queryString.currentTrashed,
viaResource: this.queryString.viaResource,
viaResourceId: this.queryString.viaResourceId,
viaRelationship: this.queryString.viaRelationship,
}
},
/**
* Get all of the available actions.
*/
allActions() {
return this.actions.concat(this.pivotActions.actions)
},
/**
* Return the selected action being executed.
*/
selectedAction() {
if (this.selectedActionKey) {
return _.find(this.allActions, a => a.uriKey == this.selectedActionKey)
}
},
/**
* Determine if the selected action is a pivot action.
*/
selectedActionIsPivotAction() {
return (
this.hasPivotActions &&
Boolean(
_.find(this.pivotActions.actions, a => a === this.selectedAction)
)
)
},
/**
* Get all of the available actions for the resource.
*/
availableActions() {
return _(this.actions)
.filter(action => {
if (this.selectedResources.length == 0) {
return action.standalone
}
return true
})
.value()
},
/**
* Get all of the available pivot actions for the resource.
*/
availablePivotActions() {
return _(this.pivotActions.actions)
.filter(action => {
if (this.selectedResources.length == 0) {
return action.standalone
}
if (this.selectedResources != 'all') {
return true
}
return action.availableForEntireResource
})
.value()
},
/**
* Determine whether there are any pivot actions
*/
hasPivotActions() {
return this.availablePivotActions.length > 0
},
},
}

25
nova/resources/js/mixins/HandlesUploads.js vendored Executable file
View File

@@ -0,0 +1,25 @@
export default {
data: () => ({ isWorking: false, fileUploadsCount: 0 }),
methods: {
/**
* Handle file upload finishing
*/
handleFileUploadFinished() {
this.fileUploadsCount--
if (this.fileUploadsCount < 1) {
this.fileUploadsCount = 0
this.isWorking = false
}
},
/**
* Handle file upload starting
*/
handleFileUploadStarted() {
this.isWorking = true
this.fileUploadsCount++
},
},
}

59
nova/resources/js/mixins/HasActions.js vendored Executable file
View File

@@ -0,0 +1,59 @@
export default {
data: () => ({
actions: [],
pivotActions: null,
}),
computed: {
/**
* Determine whether there are any standalone actions.
*/
haveStandaloneActions() {
return _.filter(this.allActions, a => a.standalone == true).length > 0
},
/**
* Return the available actions.
*/
availableActions() {
return this.actions
},
/**
* Determine if the resource has any pivot actions available.
*/
hasPivotActions() {
return this.pivotActions && this.pivotActions.actions.length > 0
},
/**
* Get the name of the pivot model for the resource.
*/
pivotName() {
return this.pivotActions ? this.pivotActions.name : ''
},
/**
* Determine if the resource has any actions available.
*/
actionsAreAvailable() {
return this.allActions.length > 0
},
/**
* Get all of the actions available to the resource.
*/
allActions() {
return this.hasPivotActions
? this.actions.concat(this.pivotActions.actions)
: this.actions
},
/**
* Get the selected resources for the action selector.
*/
selectedResourcesForActionSelector() {
return this.selectAllMatchingChecked ? 'all' : this.selectedResourceIds
},
},
}

44
nova/resources/js/mixins/Localization.js vendored Executable file
View File

@@ -0,0 +1,44 @@
export default {
methods: {
/**
* Translate the given key.
*/
__(key, replace) {
var translation = window.config.translations[key]
? window.config.translations[key]
: key
_.forEach(replace, (value, key) => {
key = new String(key)
if (value === null) {
console.error(
`Translation '${translation}' for key '${key}' contains a null replacement.`
)
return
}
value = new String(value)
const searches = [
':' + key,
':' + key.toUpperCase(),
':' + key.charAt(0).toUpperCase() + key.slice(1),
]
const replacements = [
value,
value.toUpperCase(),
value.charAt(0).toUpperCase() + value.slice(1),
]
for (var i = searches.length - 1; i >= 0; i--) {
translation = translation.replace(searches[i], replacements[i])
}
})
return translation
},
},
}

7
nova/resources/js/mixins/ThemingClasses.js vendored Executable file
View File

@@ -0,0 +1,7 @@
export default {
mounted() {
if (this.$el && this.$el.classList !== undefined) {
this.$el.classList.add(`nova-${_.kebabCase(this.$options.name)}`)
}
},
}