Skip to content
Snippets Groups Projects
Commit 2a6fb577 authored by Shinya Maeda's avatar Shinya Maeda
Browse files

Revert "Decouple FE"

This reverts commit d7401cd6.
parent d7401cd6
No related branches found
No related tags found
No related merge requests found
Showing
with 118 additions and 12 deletions
app/assets/images/ci_favicons/canary/favicon_status_scheduled.ico

5.3 KiB

app/assets/images/ci_favicons/favicon_status_scheduled.png

1.05 KiB

Loading
Loading
@@ -370,3 +370,23 @@ window.gl.utils = {
getTimeago,
localTimeAgo,
};
/**
* Formats milliseconds as timestamp (e.g. 01:02:03).
*
* @param milliseconds
* @returns {string}
*/
export const formatTime = milliseconds => {
const remainingSeconds = Math.floor(milliseconds / 1000) % 60;
const remainingMinutes = Math.floor(milliseconds / 1000 / 60) % 60;
const remainingHours = Math.floor(milliseconds / 1000 / 60 / 60);
let formattedTime = '';
if (remainingHours < 10) formattedTime += '0';
formattedTime += `${remainingHours}:`;
if (remainingMinutes < 10) formattedTime += '0';
formattedTime += `${remainingMinutes}:`;
if (remainingSeconds < 10) formattedTime += '0';
formattedTime += remainingSeconds;
return formattedTime;
};
<script>
import { s__, sprintf } from '~/locale';
import { formatTime } from '~/lib/utils/datetime_utility';
import eventHub from '../event_hub';
import icon from '../../vue_shared/components/icon.vue';
import tooltip from '../../vue_shared/directives/tooltip';
Loading
Loading
@@ -22,10 +24,17 @@ export default {
};
},
methods: {
onClickAction(endpoint) {
onClickAction(action) {
const confirmationMessage = sprintf(s__("DelayedJobs|Are you sure you want to run %{jobName} immediately? This job will run automatically after it's timer finishes."), { jobName: action.name });
// https://gitlab.com/gitlab-org/gitlab-ce/issues/52099
// eslint-disable-next-line no-alert
if (!window.confirm(confirmationMessage)) {
return;
}
this.isLoading = true;
 
eventHub.$emit('postAction', endpoint);
eventHub.$emit('postAction', action.path);
},
 
isActionDisabled(action) {
Loading
Loading
@@ -35,6 +44,11 @@ export default {
 
return !action.playable;
},
remainingTime(action) {
const remainingMilliseconds = new Date(action.scheduled_at).getTime() - Date.now();
return formatTime(remainingMilliseconds);
},
},
};
</script>
Loading
Loading
@@ -63,17 +77,24 @@ export default {
 
<ul class="dropdown-menu dropdown-menu-right">
<li
v-for="(action, i) in actions"
:key="i"
v-for="action in actions"
:key="action.path"
>
<button
:class="{ disabled: isActionDisabled(action) }"
:disabled="isActionDisabled(action)"
type="button"
class="js-pipeline-action-link no-btn btn"
@click="onClickAction(action.path)"
@click="onClickAction(action)"
>
{{ action.name }}
<span
v-if="action.scheduled_at"
class="pull-right"
>
<icon name="clock" />
{{ remainingTime(action) }}
</span>
</button>
</li>
</ul>
Loading
Loading
Loading
Loading
@@ -59,6 +59,9 @@ export default {
};
},
computed: {
actions() {
return [...this.pipeline.details.manual_actions, ...this.pipeline.details.scheduled_actions];
},
/**
* If provided, returns the commit tag.
* Needed to render the commit component column.
Loading
Loading
@@ -321,8 +324,8 @@ export default {
>
<div class="btn-group table-action-buttons">
<pipelines-actions-component
v-if="pipeline.details.manual_actions.length"
:actions="pipeline.details.manual_actions"
v-if="actions.length > 0"
:actions="actions"
/>
 
<pipelines-artifacts-component
Loading
Loading
Loading
Loading
@@ -360,6 +360,10 @@
i {
color: $gl-text-color-secondary;
}
svg {
fill: $gl-text-color-secondary;
}
}
 
.clone-dropdown-btn a {
Loading
Loading
Loading
Loading
@@ -64,6 +64,7 @@
}
}
 
.ci-status-icon-scheduled,
.ci-status-icon-manual {
svg {
fill: $gl-text-color;
Loading
Loading
Loading
Loading
@@ -760,6 +760,7 @@
}
 
&.ci-status-icon-canceled,
&.ci-status-icon-scheduled,
&.ci-status-icon-disabled,
&.ci-status-icon-not-found,
&.ci-status-icon-manual {
Loading
Loading
Loading
Loading
@@ -27,6 +27,7 @@
 
&.ci-canceled,
&.ci-disabled,
&.ci-scheduled,
&.ci-manual {
color: $gl-text-color;
border-color: $gl-text-color;
Loading
Loading
Loading
Loading
@@ -110,6 +110,13 @@ class Projects::JobsController < Projects::ApplicationController
redirect_to build_path(@build)
end
 
def unschedule
return respond_422 unless @build.scheduled?
@build.unschedule!
redirect_to build_path(@build)
end
def status
render json: BuildSerializer
.new(project: @project, current_user: @current_user)
Loading
Loading
Loading
Loading
@@ -20,6 +20,8 @@ module CiStatusHelper
'passed with warnings'
when 'manual'
'waiting for manual action'
when 'scheduled'
'waiting for delayed job'
else
status
end
Loading
Loading
@@ -39,6 +41,8 @@ module CiStatusHelper
s_('CiStatusText|passed')
when 'manual'
s_('CiStatusText|blocked')
when 'scheduled'
s_('CiStatusText|scheduled')
else
# All states are already being translated inside the detailed statuses:
# :running => Gitlab::Ci::Status::Running
Loading
Loading
@@ -83,6 +87,8 @@ module CiStatusHelper
'status_skipped'
when 'manual'
'status_manual'
when 'scheduled'
'status_scheduled'
else
'status_canceled'
end
Loading
Loading
Loading
Loading
@@ -21,9 +21,17 @@ module TimeHelper
"#{from.to_s(:short)} - #{to.to_s(:short)}"
end
 
def duration_in_numbers(duration)
time_format = duration < 1.hour ? "%M:%S" : "%H:%M:%S"
def duration_in_numbers(duration_in_seconds, allow_overflow = false)
if allow_overflow
seconds = duration_in_seconds % 1.minute
minutes = (duration_in_seconds / 1.minute) % (1.hour / 1.minute)
hours = duration_in_seconds / 1.hour
 
Time.at(duration).utc.strftime(time_format)
"%02d:%02d:%02d" % [hours, minutes, seconds]
else
time_format = duration_in_seconds < 1.hour ? "%M:%S" : "%H:%M:%S"
Time.at(duration_in_seconds).utc.strftime(time_format)
end
end
end
Loading
Loading
@@ -35,6 +35,10 @@ module Ci
"#{subject.name} - #{detailed_status.status_tooltip}"
end
 
def execute_in
scheduled? && scheduled_at && [0, scheduled_at - Time.now].max
end
private
 
def tooltip_for_badge
Loading
Loading
Loading
Loading
@@ -8,7 +8,8 @@ class CommitStatusPresenter < Gitlab::View::Presenter::Delegated
stuck_or_timeout_failure: 'There has been a timeout failure or the job got stuck. Check your timeout limits or try again',
runner_system_failure: 'There has been a runner system failure, please try again',
missing_dependency_failure: 'There has been a missing dependency failure',
runner_unsupported: 'Your runner is outdated, please upgrade your runner'
runner_unsupported: 'Your runner is outdated, please upgrade your runner',
stale_schedule: 'Delayed job could not be executed by some reason, please try again'
}.freeze
 
private_constant :CALLOUT_FAILURE_MESSAGES
Loading
Loading
Loading
Loading
@@ -12,6 +12,11 @@ class BuildActionEntity < Grape::Entity
end
 
expose :playable?, as: :playable
expose :scheduled_at, if: -> (build) { build.scheduled? }
expose :unschedule_path, if: -> (build) { build.scheduled? } do |build|
unschedule_project_job_path(build.project, build)
end
 
private
 
Loading
Loading
Loading
Loading
@@ -25,6 +25,7 @@ class JobEntity < Grape::Entity
end
 
expose :playable?, as: :playable
expose :scheduled_at
expose :created_at
expose :updated_at
expose :detailed_status, as: :status, with: DetailedStatusEntity
Loading
Loading
Loading
Loading
@@ -5,5 +5,6 @@ class PipelineDetailsEntity < PipelineEntity
expose :ordered_stages, as: :stages, using: StageEntity
expose :artifacts, using: BuildArtifactEntity
expose :manual_actions, using: BuildActionEntity
expose :scheduled_actions, using: BuildActionEntity
end
end
Loading
Loading
@@ -13,6 +13,7 @@ class PipelineSerializer < BaseSerializer
:cancelable_statuses,
:trigger_requests,
:manual_actions,
:scheduled_actions,
:artifacts,
{
pending_builds: :project,
Loading
Loading
Loading
Loading
@@ -47,7 +47,9 @@
%span.badge.badge-info triggered
- if job.try(:allow_failure)
%span.badge.badge-danger allowed to fail
- if job.action?
- if job.schedulable?
%span.badge.badge-info= s_('DelayedJobs|scheduled')
- elsif job.action?
%span.badge.badge-info manual
 
- if pipeline_link
Loading
Loading
@@ -101,6 +103,24 @@
- if job.active?
= link_to cancel_project_job_path(job.project, job, return_to: request.original_url), method: :post, title: 'Cancel', class: 'btn btn-build' do
= icon('remove', class: 'cred')
- elsif job.scheduled?
.btn-group
.btn.btn-default.has-tooltip{ disabled: true,
title: job.scheduled_at }
= sprite_icon('planning')
= duration_in_numbers(job.execute_in, true)
- confirmation_message = s_("DelayedJobs|Are you sure you want to run %{job_name} immediately? This job will run automatically after it's timer finishes.") % { job_name: job.name }
= link_to play_project_job_path(job.project, job, return_to: request.original_url),
method: :post,
title: s_('DelayedJobs|Start now'),
class: 'btn btn-default btn-build has-tooltip',
data: { confirm: confirmation_message } do
= sprite_icon('play')
= link_to unschedule_project_job_path(job.project, job, return_to: request.original_url),
method: :post,
title: s_('DelayedJobs|Unschedule'),
class: 'btn btn-default btn-build has-tooltip' do
= sprite_icon('time-out')
- elsif allow_retry
- if job.playable? && !admin && can?(current_user, :update_build, job)
= link_to play_project_job_path(job.project, job, return_to: request.original_url), method: :post, title: 'Play', class: 'btn btn-build' do
Loading
Loading
<svg width="14" height="14" viewBox="0 0 14 14" xmlns="http://www.w3.org/2000/svg"><circle cx="7" cy="7" r="7"/><circle fill="#FFF" cx="7" cy="7" r="6"/><g transform="translate(2.75 2.75)" fill-rule="nonzero"><path d="M4.165 7.81a3.644 3.644 0 1 1 0-7.29 3.644 3.644 0 0 1 0 7.29zm0-1.042a2.603 2.603 0 1 0 0-5.206 2.603 2.603 0 0 0 0 5.206z"/><rect x="3.644" y="2.083" width="1.041" height="2.603" rx=".488"/><rect x="3.644" y="3.644" width="2.083" height="1.041" rx=".488"/></g></svg>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment