Skip to content
This repository was archived by the owner on Feb 21, 2025. It is now read-only.

Commit 08bf613

Browse files
author
pmandrik
committed
add extra button
1 parent 148aedf commit 08bf613

File tree

5 files changed

+92
-9
lines changed

5 files changed

+92
-9
lines changed

runregistry_backend/controllers/run.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const {
1616
const { update_or_create_dataset } = require('./dataset');
1717
const { create_new_version } = require('./version');
1818
const { fill_dataset_triplet_cache } = require('./dataset_triplet_cache');
19-
const { manually_update_a_run } = require('../cron/2.save_or_update_runs');
19+
const { manually_update_a_run , manually_update_a_run_reset_rr_attributes } = require('../cron/2.save_or_update_runs');
2020
const {
2121
create_offline_waiting_datasets,
2222
} = require('../cron_datasets/1.create_datasets');
@@ -578,6 +578,32 @@ exports.refreshRunClassAndComponents = async (req, res) => {
578578
res.json(saved_run);
579579
};
580580

581+
exports.resetAndRefreshRunRRatributes = async (req, res) => {
582+
const { run_number } = req.params;
583+
const email = req.get('email');
584+
const previously_saved_run = await Run.findByPk(run_number);
585+
if (previously_saved_run === null) {
586+
throw 'Run not found';
587+
}
588+
if (previously_saved_run.rr_attributes.state !== 'OPEN') {
589+
throw 'Run must be in state OPEN to be refreshed';
590+
}
591+
592+
await manually_update_a_run_reset_rr_attributes(run_number, {
593+
email,
594+
comment: `${email} requested reset and refresh from OMS`,
595+
});
596+
const saved_run = await Run.findByPk(run_number, {
597+
include: [
598+
{
599+
model: DatasetTripletCache,
600+
attributes: ['triplet_summary'],
601+
},
602+
],
603+
});
604+
res.json(saved_run);
605+
};
606+
581607
exports.moveRun = async (req, res) => {
582608
const { to_state } = req.params;
583609
const { run_number } = req.body;

runregistry_backend/cron/2.save_or_update_runs.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,33 @@ exports.manually_update_a_run = async (
270270
});
271271
};
272272

273+
exports.manually_update_a_run_reset_rr_attributes = (
274+
run_number,
275+
{ email, comment, manually_significant, atomic_version }
276+
) => {
277+
// get rr_attributes:
278+
const { data: saved_run } = await axios.get(`${API_URL}/runs/${run_number}`);
279+
const previous_rr_attributes = None;
273280

274-
281+
if (previous_rr_attributes.state !== 'OPEN') {
282+
throw 'Run must be in state OPEN to be refreshed';
283+
}
284+
// get oms_attributes:
285+
const endpoint = `${OMS_URL}/${OMS_SPECIFIC_RUN(run_number)}`;
286+
const {
287+
data: { data: fetched_run },
288+
} = await instance.get(endpoint, {
289+
headers: {
290+
Authorization: `Bearer ${await getToken()}`,
291+
},
292+
});
293+
const run_oms_attributes = fetched_run[0].attributes;
294+
await exports.update_runs([run_oms_attributes], 0, {
295+
previous_rr_attributes,
296+
email,
297+
comment,
298+
manually_significant,
299+
atomic_version,
300+
});
301+
};
275302

runregistry_backend/routes/run.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ module.exports = app => {
2525
// Shifter actions:
2626
app.post('/runs/mark_significant', auth, catchAPI(Run.markSignificant));
2727
app.post('/runs/move_run/:from_state/:to_state', auth, catchAPI(Run.moveRun));
28-
app.post(
29-
'/runs/refresh_run/:run_number',
30-
catchAPI(Run.refreshRunClassAndComponents)
31-
);
28+
app.post('/runs/refresh_run/:run_number', catchAPI(Run.refreshRunClassAndComponents));
29+
app.post('/runs/reset_and_refresh_run/:run_number', catchAPI(Run.resetAndRefreshRunRRatributes));
3230
};

runregistry_frontend/components/online/manage_run/manageRun/editRunLumisections/EditRunLumisections.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ class EditRunLumisections extends Component {
7171
reverseButtons: true,
7272
});
7373
if (value) {
74-
const updated_run = await this.props.refreshRun(
75-
run.run_number
76-
);
74+
const updated_run = await this.props.refreshRun( run.run_number );
7775
await Swal(`Run updated`, '', 'success');
7876
await this.props.showManageRunModal(updated_run);
7977
this.fetchLumisections();
@@ -83,6 +81,28 @@ class EditRunLumisections extends Component {
8381
>
8482
Manually refresh component's statuses
8583
</Button>
84+
85+
<Button
86+
onClick={async (evt) => {
87+
const { value } = await Swal({
88+
type: 'warning',
89+
title: `If a status was previously edited by a shifter, it will not be updated, it will only change those untouched.`,
90+
text: '',
91+
showCancelButton: true,
92+
confirmButtonText: 'Yes',
93+
reverseButtons: true,
94+
});
95+
if (value) {
96+
const updated_run = await this.props.resetAndRefreshRun( run.run_number );
97+
await Swal(`Run updated`, '', 'success');
98+
await this.props.showManageRunModal(updated_run);
99+
this.fetchLumisections();
100+
}
101+
}}
102+
type="primary"
103+
>
104+
Reset RR attributes and refresh
105+
</Button>
86106
</div>
87107
<br />
88108

runregistry_frontend/ducks/online/runs.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ export const refreshRun = run_number =>
8383
return run;
8484
});
8585

86+
export const resetAndRefreshRun = run_number =>
87+
error_handler(async (dispatch, getState) => {
88+
let { data: run } = await axios.post(
89+
`${api_url}/runs/reset_and_refresh_run/${run_number}`,
90+
{},
91+
auth(getState)
92+
);
93+
run = formatRuns([run])[0];
94+
dispatch({ type: EDIT_RUN, payload: run });
95+
return run;
96+
});
97+
8698
// reFetch run will just refetch a run
8799
export const reFetchRun = run_number =>
88100
error_handler(async (dispatch, getState) => {

0 commit comments

Comments
 (0)