mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-11-04 12:22:47 +00:00 
			
		
		
		
	Add job namespace and remove old json_routes logic
This commit is contained in:
		@@ -3,6 +3,7 @@ nopaque.App = class App {
 | 
			
		||||
    this.socket = io({transports: ['websocket'], upgrade: false});
 | 
			
		||||
 | 
			
		||||
    // Endpoints
 | 
			
		||||
    this.jobs = new nopaque.app.endpoints.Jobs(this);
 | 
			
		||||
    this.users = new nopaque.app.endpoints.Users(this);
 | 
			
		||||
 | 
			
		||||
    // Extensions
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										37
									
								
								app/static/js/app/endpoints/jobs.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								app/static/js/app/endpoints/jobs.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,37 @@
 | 
			
		||||
nopaque.app.endpoints.Jobs = class Jobs {
 | 
			
		||||
  constructor(app) {
 | 
			
		||||
    this.app = app;
 | 
			
		||||
 | 
			
		||||
    this.socket = io('/jobs', {transports: ['websocket'], upgrade: false});
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async delete(id) {
 | 
			
		||||
    const response = await this.socket.emitWithAck('delete', id);
 | 
			
		||||
 | 
			
		||||
    if (response.status != 202) {
 | 
			
		||||
      throw new Error(`[${response.status}] ${response.statusText}`);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return response.body;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async log(id) {
 | 
			
		||||
    const response = await this.socket.emitWithAck('log', id);
 | 
			
		||||
 | 
			
		||||
    if (response.status != 200) {
 | 
			
		||||
      throw new Error(`[${response.status}] ${response.statusText}`);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return response.body;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async restart(id) {
 | 
			
		||||
    const response = await this.socket.emitWithAck('restart', id);
 | 
			
		||||
 | 
			
		||||
    if (response.status != 202) {
 | 
			
		||||
      throw new Error(`[${response.status}] ${response.statusText}`);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return response.body;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -5,8 +5,8 @@ nopaque.app.endpoints.Users = class Users {
 | 
			
		||||
    this.socket = io('/users', {transports: ['websocket'], upgrade: false});
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async get(userId) {
 | 
			
		||||
    const response = await this.socket.emitWithAck('get', userId);
 | 
			
		||||
  async get(id) {
 | 
			
		||||
    const response = await this.socket.emitWithAck('get', id);
 | 
			
		||||
 | 
			
		||||
    if (response.status !== 200) {
 | 
			
		||||
      throw new Error(`[${response.status}] ${response.statusText}`);
 | 
			
		||||
@@ -15,27 +15,29 @@ nopaque.app.endpoints.Users = class Users {
 | 
			
		||||
    return response.body;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async subscribe(userId) {
 | 
			
		||||
    const response = await this.socket.emitWithAck('subscribe', userId);
 | 
			
		||||
  async subscribe(id) {
 | 
			
		||||
    const response = await this.socket.emitWithAck('subscribe', id);
 | 
			
		||||
 | 
			
		||||
    if (response.status != 200) {
 | 
			
		||||
      throw new Error(`[${response.status}] ${response.statusText}`);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async unsubscribe(userId) {
 | 
			
		||||
    const response = await this.socket.emitWithAck('unsubscribe', userId);
 | 
			
		||||
  async unsubscribe(id) {
 | 
			
		||||
    const response = await this.socket.emitWithAck('unsubscribe', id);
 | 
			
		||||
 | 
			
		||||
    if (response.status != 200) {
 | 
			
		||||
      throw new Error(`[${response.status}] ${response.statusText}`);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async delete(userId) {
 | 
			
		||||
    const response = await this.socket.emitWithAck('delete', userId);
 | 
			
		||||
  async delete(id) {
 | 
			
		||||
    const response = await this.socket.emitWithAck('delete', id);
 | 
			
		||||
 | 
			
		||||
    if (response.status != 202) {
 | 
			
		||||
      throw new Error(`[${response.status}] ${response.statusText}`);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return response.body;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -136,8 +136,9 @@ nopaque.resource_lists.JobList = class JobList extends nopaque.resource_lists.Re
 | 
			
		||||
          }
 | 
			
		||||
        );
 | 
			
		||||
        let confirmElement = modalElement.querySelector('.action-button[data-action="confirm"]');
 | 
			
		||||
        confirmElement.addEventListener('click', (event) => {
 | 
			
		||||
          nopaque.requests.jobs.entity.delete(itemId);
 | 
			
		||||
        confirmElement.addEventListener('click', async (event) => {
 | 
			
		||||
          const message = await app.jobs.delete(itemId);
 | 
			
		||||
          app.ui.flash(message, 'job');
 | 
			
		||||
        });
 | 
			
		||||
        modal.open();
 | 
			
		||||
        break;
 | 
			
		||||
@@ -221,8 +222,9 @@ nopaque.resource_lists.JobList = class JobList extends nopaque.resource_lists.Re
 | 
			
		||||
        );
 | 
			
		||||
        let confirmElement = modalElement.querySelector('.action-button[data-action="confirm"]');
 | 
			
		||||
        confirmElement.addEventListener('click', (event) => {
 | 
			
		||||
          this.selectedItemIds.forEach(selectedItemId => {
 | 
			
		||||
            nopaque.requests.jobs.entity.delete(selectedItemId);
 | 
			
		||||
          this.selectedItemIds.forEach(async (selectedItemId) => {
 | 
			
		||||
            const message = await app.jobs.delete(selectedItemId);
 | 
			
		||||
            app.ui.flash(message, 'job');
 | 
			
		||||
          });
 | 
			
		||||
          this.selectedItemIds.clear();
 | 
			
		||||
          this.renderingItemSelection();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user