|
|
|
|
|
function apiKeyManager() {
|
|
return {
|
|
|
|
apiKeys: [],
|
|
platformStates: {},
|
|
platformFilters: {},
|
|
platformIds: [],
|
|
allPlatformsSelected: true,
|
|
currentView: 'valid',
|
|
searchTerm: '',
|
|
showAddModal: false,
|
|
showDeleteConfirm: false,
|
|
isSubmitting: false,
|
|
isDeleting: false,
|
|
isLoading: true,
|
|
errorMessage: '',
|
|
copiedId: null,
|
|
deleteKeyId: null,
|
|
deleteKeyName: '',
|
|
selectedKeys: [],
|
|
selectedPlatforms: [],
|
|
isBulkDelete: false,
|
|
newKey: {
|
|
platform: '',
|
|
name: '',
|
|
key: ''
|
|
},
|
|
showEditModal: false,
|
|
editKey: {
|
|
id: '',
|
|
name: '',
|
|
key: '',
|
|
platform: ''
|
|
},
|
|
|
|
|
|
init() {
|
|
|
|
initApiKeyManager.call(this);
|
|
},
|
|
|
|
|
|
loadApiKeys() {
|
|
return loadApiKeys.apply(this, arguments);
|
|
},
|
|
|
|
|
|
addApiKey() {
|
|
return addApiKey.apply(this, arguments);
|
|
},
|
|
|
|
|
|
deleteApiKey(id, name) {
|
|
return deleteApiKey.apply(this, arguments);
|
|
},
|
|
|
|
|
|
toggleKeySelection(keyId) {
|
|
return toggleKeySelection.apply(this, arguments);
|
|
},
|
|
|
|
|
|
togglePlatformSelection(platformId) {
|
|
return togglePlatformSelection.apply(this, arguments);
|
|
},
|
|
|
|
|
|
updatePlatformSelectionStates() {
|
|
return updatePlatformSelectionStates.apply(this, arguments);
|
|
},
|
|
|
|
|
|
getAllVisibleKeyIds() {
|
|
return getAllVisibleKeyIds.apply(this, arguments);
|
|
},
|
|
|
|
|
|
get isAllSelected() {
|
|
|
|
const allVisibleKeyIds = this.getAllVisibleKeyIds();
|
|
|
|
|
|
const filteredIds = allVisibleKeyIds.filter(id => {
|
|
const key = this.apiKeys.find(k => k.id === id);
|
|
return key && this.platformFilters[key.platform] === true;
|
|
});
|
|
|
|
|
|
return filteredIds.length > 0 &&
|
|
filteredIds.every(id => this.selectedKeys.includes(id));
|
|
},
|
|
|
|
|
|
toggleSelectAll() {
|
|
return toggleSelectAll.apply(this, arguments);
|
|
},
|
|
|
|
|
|
bulkDeleteApiKeys() {
|
|
return bulkDeleteApiKeys.apply(this, arguments);
|
|
},
|
|
|
|
|
|
bulkCopyApiKeys() {
|
|
return bulkCopyApiKeys.apply(this, arguments);
|
|
},
|
|
|
|
|
|
confirmDelete() {
|
|
return confirmDelete.apply(this, arguments);
|
|
},
|
|
|
|
|
|
copyToClipboard(text, id) {
|
|
return copyToClipboard.apply(this, arguments);
|
|
},
|
|
|
|
|
|
togglePlatform(platformId) {
|
|
return togglePlatform.apply(this, arguments);
|
|
},
|
|
|
|
|
|
getPlatformKeyCount(platformId, filtered = false) {
|
|
return getPlatformKeyCount.apply(this, arguments);
|
|
},
|
|
|
|
|
|
hasPlatformKeys(platformId) {
|
|
return hasPlatformKeys.apply(this, arguments);
|
|
},
|
|
|
|
|
|
isPlatformVisible(platformId) {
|
|
return isPlatformVisible.apply(this, arguments);
|
|
},
|
|
|
|
|
|
switchView(view) {
|
|
if (this.currentView !== view) {
|
|
|
|
const currentStateKey = `platformStates_${this.currentView}`;
|
|
localStorage.setItem(currentStateKey, JSON.stringify(this.platformStates));
|
|
|
|
|
|
this.currentView = view;
|
|
|
|
|
|
localStorage.setItem('keyView', view);
|
|
|
|
|
|
const newStateKey = `platformStates_${view}`;
|
|
const savedPlatformStates = localStorage.getItem(newStateKey);
|
|
if (savedPlatformStates) {
|
|
this.platformStates = JSON.parse(savedPlatformStates);
|
|
} else {
|
|
|
|
const platforms = this.getPlatforms();
|
|
platforms.forEach(platform => {
|
|
this.platformStates[platform.id] = true;
|
|
});
|
|
}
|
|
|
|
|
|
this.selectedKeys = [];
|
|
this.selectedPlatforms = [];
|
|
|
|
|
|
this.loadApiKeys();
|
|
}
|
|
},
|
|
|
|
|
|
isKeyVisibleInCurrentView(key) {
|
|
if (this.currentView === 'valid') {
|
|
return key.success === true;
|
|
} else if (this.currentView === 'invalid') {
|
|
return key.success === false;
|
|
}
|
|
return true;
|
|
},
|
|
|
|
|
|
getPlatforms() {
|
|
return getPlatforms.apply(this, arguments);
|
|
},
|
|
|
|
|
|
togglePlatformFilter(platformId) {
|
|
return togglePlatformFilter.apply(this, arguments);
|
|
},
|
|
|
|
|
|
toggleAllPlatformFilters() {
|
|
return toggleAllPlatformFilters.apply(this, arguments);
|
|
},
|
|
|
|
|
|
matchesSearch(name, key, notes) {
|
|
return matchesSearch.apply(this, arguments);
|
|
},
|
|
|
|
|
|
totalKeyCount() {
|
|
return totalKeyCount.apply(this, arguments);
|
|
},
|
|
|
|
|
|
editApiKey(id, name, key) {
|
|
return editApiKey.apply(this, arguments);
|
|
},
|
|
|
|
|
|
updateApiKey() {
|
|
return updateApiKey.apply(this, arguments);
|
|
},
|
|
|
|
|
|
showNotification(message, type = 'info') {
|
|
return showNotification.apply(this, arguments);
|
|
}
|
|
};
|
|
}
|
|
|