modifica - da terminare gestioen doc remoti - resto ok
This commit is contained in:
@@ -1380,7 +1380,7 @@ function browseRepo(repoId, repoNome, path) {
|
||||
function updateRemoteBreadcrumb(nome, path) {
|
||||
const bc = document.getElementById('remoteBreadcrumb');
|
||||
const parts = path.replace(/^\/+|\/+$/g, '').split('/').filter(Boolean);
|
||||
let html = '<i class="fab ' + (currentRepoBrowse && currentRepoBrowse.id ? getRepoIcon(repoIconFromId(currentRepoBrowse.id)) : 'fa-server') + ' mr-1"></i> ' + escHtml(nome);
|
||||
let html = '<i class="' + (currentRepoBrowse && currentRepoBrowse.id ? repoIconFromId(currentRepoBrowse.id) : 'fa fa-server') + ' mr-1"></i> ' + escHtml(nome);
|
||||
if (parts.length > 0 && parts[0] !== '') {
|
||||
html += ' / ' + parts.map(p => escHtml(p)).join(' / ');
|
||||
}
|
||||
|
||||
@@ -1625,6 +1625,7 @@ if (window.location.hash === '#email') {
|
||||
|
||||
// ===== REPOSITORY REMOTI =====
|
||||
let repositories = @json($repositories);
|
||||
let newToken = @json($googleDriveNewToken);
|
||||
|
||||
function resetRepoForm() {
|
||||
document.getElementById('repoForm').action = '{{ route('storage-repositories.store') }}';
|
||||
@@ -1633,6 +1634,7 @@ function resetRepoForm() {
|
||||
document.getElementById('repoForm').reset();
|
||||
document.getElementById('repoId').value = '';
|
||||
document.getElementById('repo_is_active').checked = true;
|
||||
setGdAuthStatus(false, '');
|
||||
toggleRepoConfigFields();
|
||||
}
|
||||
|
||||
@@ -1640,6 +1642,59 @@ function toggleRepoConfigFields() {
|
||||
const tipo = document.getElementById('repo_tipo').value;
|
||||
document.getElementById('webdavFields').style.display = tipo === 'webdav' ? '' : 'none';
|
||||
document.getElementById('googleDriveFields').style.display = tipo === 'google_drive' ? '' : 'none';
|
||||
if (tipo === 'google_drive') {
|
||||
updateGdAuthUrl();
|
||||
}
|
||||
}
|
||||
|
||||
function setGdAuthStatus(authorized, clientId) {
|
||||
const statusEl = document.getElementById('gdAuthStatus');
|
||||
const btn = document.getElementById('gdAuthBtn');
|
||||
if (authorized) {
|
||||
statusEl.innerHTML = '<span class="text-success"><i class="fas fa-check-circle mr-1"></i> Autorizzato</span>';
|
||||
btn.innerHTML = '<i class="fas fa-refresh mr-1"></i> Ri-autorizza con Google';
|
||||
} else {
|
||||
statusEl.innerHTML = '<span class="text-muted"><i class="fas fa-circle mr-1"></i> Non autorizzato</span>';
|
||||
btn.innerHTML = '<i class="fas fa-google mr-1"></i> Autorizza con Google';
|
||||
}
|
||||
}
|
||||
|
||||
function updateGdAuthUrl() {
|
||||
const clientId = document.getElementById('gd_client_id').value.trim();
|
||||
const clientSecret = document.getElementById('gd_client_secret').value.trim();
|
||||
const repoId = document.getElementById('repoId').value;
|
||||
const nome = document.getElementById('repo_nome').value.trim();
|
||||
const isActive = document.getElementById('repo_is_active').checked ? '1' : '0';
|
||||
const rootFolderId = document.getElementById('gd_root_folder_id').value.trim();
|
||||
const btn = document.getElementById('gdAuthBtn');
|
||||
if (clientId && clientSecret) {
|
||||
const params = new URLSearchParams({
|
||||
client_id: clientId,
|
||||
client_secret: clientSecret,
|
||||
repo_id: repoId || '0',
|
||||
nome: nome,
|
||||
is_active: isActive,
|
||||
root_folder_id: rootFolderId || 'root',
|
||||
});
|
||||
btn.href = '{{ route('google-drive.redirect') }}?' + params.toString();
|
||||
btn.classList.remove('disabled');
|
||||
} else {
|
||||
btn.href = '#';
|
||||
btn.classList.add('disabled');
|
||||
}
|
||||
}
|
||||
|
||||
function startGdAuth() {
|
||||
const clientId = document.getElementById('gd_client_id').value.trim();
|
||||
const clientSecret = document.getElementById('gd_client_secret').value.trim();
|
||||
if (!clientId || !clientSecret) {
|
||||
alert('Inserisci Client ID e Client Secret prima di autorizzare.');
|
||||
return false;
|
||||
}
|
||||
// Open in same window (full redirect flow)
|
||||
updateGdAuthUrl();
|
||||
window.location.href = document.getElementById('gdAuthBtn').href;
|
||||
return false;
|
||||
}
|
||||
|
||||
function editRepo(id) {
|
||||
@@ -1664,10 +1719,11 @@ function editRepo(id) {
|
||||
document.getElementById('gd_client_id').value = config.client_id || '';
|
||||
document.getElementById('gd_client_secret').value = '';
|
||||
document.getElementById('gd_client_secret').placeholder = config.client_secret ? '......' : '';
|
||||
document.getElementById('gd_refresh_token').value = '';
|
||||
document.getElementById('gd_refresh_token').placeholder = config.refresh_token ? '......' : '';
|
||||
document.getElementById('gd_refresh_token').value = config.refresh_token || '';
|
||||
document.getElementById('gd_root_folder_id').value = config.root_folder_id || 'root';
|
||||
|
||||
const hasRefreshToken = !!(config.refresh_token && config.refresh_token !== '');
|
||||
setGdAuthStatus(hasRefreshToken, config.client_id || '');
|
||||
toggleRepoConfigFields();
|
||||
$('#repoModal').modal('show');
|
||||
}
|
||||
@@ -1736,6 +1792,25 @@ $(document).ready(function() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (newToken && newToken.refresh_token) {
|
||||
// Auto-open modal after OAuth callback — preserve nome and other fields
|
||||
document.getElementById('repoForm').action = '{{ route('storage-repositories.store') }}';
|
||||
document.getElementById('repoMethod').value = 'POST';
|
||||
document.getElementById('repoModalTitle').textContent = 'Nuovo Repository Remoto';
|
||||
document.getElementById('repoForm').reset();
|
||||
document.getElementById('repoId').value = '';
|
||||
document.getElementById('repo_nome').value = newToken.nome || '';
|
||||
document.getElementById('repo_tipo').value = 'google_drive';
|
||||
document.getElementById('repo_is_active').checked = newToken.is_active !== '0';
|
||||
document.getElementById('gd_client_id').value = newToken.client_id || '';
|
||||
document.getElementById('gd_client_secret').value = newToken.client_secret || '';
|
||||
document.getElementById('gd_refresh_token').value = newToken.refresh_token;
|
||||
document.getElementById('gd_root_folder_id').value = newToken.root_folder_id || 'root';
|
||||
setGdAuthStatus(true, newToken.client_id || '');
|
||||
toggleRepoConfigFields();
|
||||
$('#repoModal').modal('show');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -1828,35 +1903,46 @@ $(document).ready(function() {
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="gd_client_id">Client ID *</label>
|
||||
<input type="text" name="config[client_id]" id="gd_client_id" class="form-control" placeholder="Google Client ID">
|
||||
<input type="text" name="config[client_id]" id="gd_client_id" class="form-control" placeholder="Google Client ID" oninput="updateGdAuthUrl()">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="gd_client_secret">Client Secret *</label>
|
||||
<input type="text" name="config[client_secret]" id="gd_client_secret" class="form-control" placeholder="Google Client Secret">
|
||||
<input type="password" name="config[client_secret]" id="gd_client_secret" class="form-control" placeholder="Google Client Secret" oninput="updateGdAuthUrl()">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="gd_refresh_token">Refresh Token *</label>
|
||||
<input type="text" name="config[refresh_token]" id="gd_refresh_token" class="form-control" placeholder="OAuth Refresh Token">
|
||||
<input type="hidden" name="config[refresh_token]" id="gd_refresh_token" value="">
|
||||
<div class="mb-3">
|
||||
<label class="d-block">Autorizzazione Google</label>
|
||||
<div id="gdAuthStatus" class="mb-2">
|
||||
<span class="text-muted"><i class="fas fa-circle mr-1"></i> Non autorizzato</span>
|
||||
</div>
|
||||
<a id="gdAuthBtn" href="#" class="btn btn-danger btn-sm" target="_blank" onclick="return startGdAuth()">
|
||||
<i class="fas fa-google mr-1"></i> Autorizza con Google
|
||||
</a>
|
||||
<small class="d-block text-muted mt-1">
|
||||
Dopo aver cliccato, verrai reindirizzato a Google per autorizzare l'app.
|
||||
Al termine, il Refresh Token verrà salvato automaticamente.
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="gd_root_folder_id">Root Folder ID</label>
|
||||
<input type="text" name="config[root_folder_id]" id="gd_root_folder_id" class="form-control" value="root" placeholder="root">
|
||||
<input type="text" name="config[root_folder_id]" id="gd_root_folder_id" class="form-control" value="root" placeholder="root" oninput="updateGdAuthUrl()">
|
||||
<small class="text-muted">ID della cartella Google Drive, default: root</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="alert alert-info">
|
||||
<i class="fas fa-info-circle mr-2"></i>
|
||||
Per ottenere le credenziali OAuth: <a href="https://console.cloud.google.com/" target="_blank">Google Cloud Console</a>
|
||||
→ API & Services → Credentials → Crea OAuth Client ID (Desktop App).
|
||||
<strong>Prima volta?</strong> Crea il progetto in <a href="https://console.cloud.google.com/" target="_blank">Google Cloud Console</a>
|
||||
→ API & Services → Credentials → Crea OAuth Client ID (Web Application).
|
||||
Aggiungi <code>{{ url('/auth/google-drive/callback') }}</code> come <strong>Authorized Redirect URI</strong>.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -256,6 +256,7 @@ $appName = \App\Models\AppSetting::getAppName() ?? 'Glastree';
|
||||
<script src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/admin-lte@3.2/dist/js/adminlte.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
@yield('scripts')
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user