phpmyadmin / error-reporting-server

phpMyAdmin server side component for the error reporting system
MIT License
20 stars 28 forks source link

Mass merge from listing #70

Open nijel opened 9 years ago

nijel commented 9 years ago

Sometimes it's clear from the listing of issues that these are same, so there should be a mass merge option.

williamdes commented 5 years ago

I use a tampermonkey snippet to fix the issue :smile:

// ==UserScript==
// @name         pma reports
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  hack report server
// @author       William Desportes
// @match        https://reports.phpmyadmin.net/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const sameAs = localStorage.getItem('sameAsRememeber');
    const urlBase = 'https://reports.phpmyadmin.net/reports/mark_related_to/';
    var done = 0;
    var max = 0;
    var concurrent = async (xs, f, n=Infinity) => {
        const finished = Symbol();
        let promises = xs.slice(0, n).map(f), others = xs.slice(n);
        while (promises.length) {
            await Promise.race(promises.map(promise => promise.then(() => {promise[finished] = true;})));
            promises = promises.filter(promise => !promise[finished]);
            promises.push(...others.splice(0, n - promises.length).map(f));
        }
    };
    const markReport = (done, total, reportId) => {
        $('input[type="checkbox"][value="'+reportId+'"]').prop('checked' , false);
        $("#mark_same_as").val('In progress ... (' +done+'/'+total+')');
        if (done === total) {
            $("#mark_same_as").val('All done');
            $('#resultsForm_checkall').prop('checked' , false);
        }
    };

    const processMarkReports = (ticketId, reports) => {
        done = 0;
        max = reports.length;
        concurrent(reports, (reportId) => {
            console.log("Mark same "+reportId+" as "+ticketId);
            return $.post(urlBase + reportId, {
                related_to: ticketId
            }, (result) => {
                done++;
                markReport(done, max, reportId)
            });
        }, 10);
    }

    $('#reports_table_length > label > select').append('<option value="300">300</option>');
    $('#reports_table_length > label > select').append('<option value="500">500</option>');
    $('#reports_table_length > label > select').append('<option value="1000">1000</option>');
    $('#reports_table_length > label > select').append('<option value="1500">1500</option>');
    $('#state-form > div:nth-child(2)').append(`
<input type="number" id="same_as"/>
<input type="button" value="Mark same as" id="mark_same_as" class="btn btn-primary"/>
<input type="button" value="Clear value" id="clear_sameAsRememeber" class="btn btn-primary"/>
`);
    $('#same_as').val(sameAs);
    $("#clear_sameAsRememeber").on('click', function () {
        localStorage.setItem('sameAsRememeber', '');
        $("#same_as").val('');
    });
    $("#mark_same_as").on('click', function () {
        const ticketId = $('#same_as').val();

        localStorage.setItem('sameAsRememeber', ticketId);
        var sameReports = [];
        $.each($("input[name='reports[]']:checked"), function (){
            let reportId = $(this).val();
            if(reportId !== ticketId) {
                sameReports.push(reportId);
            }
        });

        console.log(ticketId, sameReports);
        processMarkReports(ticketId, sameReports);
    });
})();