Skip to content

Commit

Permalink
Added notification alerts for failed AJAX queries
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshStark committed Mar 30, 2019
1 parent b99a597 commit c100aad
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ private void synchroniseRepository(String repositoryName, SynchronisationContext
DockerHubImage dockerHubImage = images.get(i);
Image image = configureImage(repository.getId(), dockerHubImage, context);

String maskedVersion = getMaskedVersion(repository.getName(), image.getName(), image.getVersionMask(), context);
LOGGER.debug("Updated image version using mask. Mask=" + image.getVersionMask() + ", MaskedVersion=" + maskedVersion);
String versionMask = getVersionMask(repository.getVersionMask(), image.getVersionMask());
String maskedVersion = getMaskedVersion(repository.getName(), image.getName(), versionMask, context);
LOGGER.debug("Updated image version using mask. Mask=" + versionMask + ", MaskedVersion=" + maskedVersion);

image.withPullCount(dockerHubImage.getPullCount()).withVersion(maskedVersion);

Expand All @@ -150,6 +151,10 @@ private void synchroniseRepository(String repositoryName, SynchronisationContext
}
}

private String getVersionMask(String repositoryMask, String imageMask) {
return imageMask == null ? repositoryMask : imageMask;
}

private String getMaskedVersion(String repositoryName, String imageName, String versionMask, SynchronisationContext context) {

String tag = context.getDockerHubDelegate().fetchLatestImageTag(repositoryName, imageName);
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/assets/css/fleet.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
body {
color: #666;
position: relative;
}

a {
Expand Down Expand Up @@ -174,6 +175,15 @@ i.fas, i.far {
margin-right: 5px;
}

.fleet-notifications {

position: fixed;
bottom: 25px;
right: 25px;
max-width: calc(100% - 25px);
z-index: 1000;
}

/*
*****
iOS Switches copied from: https://codepen.io/aorcsik/pen/OPMyQp
Expand Down
27 changes: 24 additions & 3 deletions src/main/resources/assets/js/fleet.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,29 @@ var ajaxManager = (function($) {

var handleError = function(jqXHR, textStatus, handleError) {

var error = JSON.parse(jqXHR.responseText);
console.error(error);
if (jqXHR.status === 403) {

var notification = $(
'<div class="fleet-alert fleet-alert--warning">' +
'<i class="fas fa-exclamation-triangle text-warning"></i> Permission denied. Has your session expired?' +
'</div>'
);

} else {

var message = JSON.parse(jqXHR.responseText).data;

var notification = $(
'<div class="fleet-alert fleet-alert--warning">' +
'<i class="fas fa-exclamation-triangle text-warning"></i> ' + message +
'</div>'
);
}

$('.fleet-notifications').append(notification);
notification.delay(3000).fadeOut(2000, function() {
$(this).remove();
});
};

var call = function(param, onDone) {
Expand Down Expand Up @@ -195,7 +216,7 @@ var imageListManager = (function($) {
var imageId = getImageId(row);

modal.find('#image-deprecation-reason').val('');
modal.find('#selected-deprecation-image-name').text('Deprecation notice for' + getImageName(row));
modal.find('#selected-deprecation-image-name').text('Deprecation notice for ' + getImageName(row));
modal.find('#submit-deprecation-change').data('image-id', imageId);
modal.find('#submit-deprecation-change').data('trigger-option', option.attr('id'));
};
Expand Down
176 changes: 176 additions & 0 deletions src/main/resources/db/migration/V1.7__RemoveCoalesce.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
DELIMITER //

DROP PROCEDURE `Image_Get`//
CREATE PROCEDURE `Image_Get`
(
in_id INT
)
BEGIN

SELECT
images.`id` AS `ImageId`,
images.`repository` AS `RepositoryId`,
images.`name` AS `ImageName`,
images.`pulls` AS `ImagePullCount`,
images.`latest_version` AS `ImageVersion`,
images.`version_mask` AS `ImageVersionMask`,
images.`hidden` AS `ImageHidden`,
images.`unstable` AS `ImageUnstable`,
images.`deprecated` AS `ImageDeprecated`,
images.`deprecation_reason` AS `ImageDeprecationReason`,
images.`modified` AS `ModifiedTime`
FROM
Images images
WHERE
images.`id` = in_id;

END;
//

DROP PROCEDURE `Image_GetByName`//
CREATE PROCEDURE `Image_GetByName`
(
in_repo_id INT,
in_image_name VARCHAR(255)
)
BEGIN

SELECT
images.`id` AS `ImageId`,
images.`repository` AS `RepositoryId`,
images.`name` AS `ImageName`,
images.`pulls` AS `ImagePullCount`,
images.`latest_version` AS `ImageVersion`,
images.`version_mask` AS `ImageVersionMask`,
images.`hidden` AS `ImageHidden`,
images.`unstable` AS `ImageUnstable`,
images.`deprecated` AS `ImageDeprecated`,
images.`deprecation_reason` AS `ImageDeprecationReason`,
images.`modified` AS `ModifiedTime`
FROM
Images images
INNER JOIN
Repositories repos ON repos.`id` = images.`repository`
WHERE
images.`name` = in_image_name AND repos.`id` = in_repo_id;

END;
//

DROP PROCEDURE `Image_Save`//
CREATE PROCEDURE `Image_Save`
(
in_id INT,
in_repository INT,
in_name VARCHAR(255),
in_pull_count BIGINT,
in_version VARCHAR(100),
in_version_mask VARCHAR(255),
in_hidden TINYINT,
in_unstable TINYINT,
in_deprecated TINYINT,
in_deprecation_reason VARCHAR(255),

OUT out_id INT,
OUT out_status INT,
OUT out_message VARCHAR(100)
)
BEGIN

IF in_id IS NULL THEN

INSERT INTO Images
(
`repository`,
`name`,
`pulls`,
`latest_version`,
`version_mask`,
`hidden`,
`unstable`,
`deprecated`,
`deprecation_reason`
)
VALUES
(
in_repository,
in_name,
in_pull_count,
in_version,
in_version_mask,
in_hidden,
in_unstable,
in_deprecated,
in_deprecation_reason
);

SET out_id = LAST_INSERT_ID();

ELSE

UPDATE Images
SET
`name` = in_name,
`pulls` = in_pull_count,
`latest_version` = in_version,
`version_mask` = in_version_mask,
`hidden` = in_hidden,
`unstable` = in_unstable,
`deprecated` = in_deprecated,
`deprecation_reason` = in_deprecation_reason
WHERE
`id` = in_id;

SET out_id = in_id;

END IF;

SET out_status = 0;
SET out_message = "OK";

END;
//

DROP PROCEDURE `Image_GetAll`//
CREATE PROCEDURE `Image_GetAll`
(
in_repository INT,

OUT out_total_count INT
)
BEGIN

SELECT
COUNT(*)
INTO
out_total_count
FROM
Images
WHERE
`repository` = in_repository;

SELECT
images.`id` AS `ImageId`,
images.`repository` AS `RepositoryId`,
images.`name` AS `ImageName`,
images.`pulls` AS `ImagePullCount`,
images.`latest_version` AS `ImageVersion`,
images.`version_mask` AS `ImageVersionMask`,
images.`hidden` AS `ImageHidden`,
images.`unstable` AS `ImageUnstable`,
images.`deprecated` AS `ImageDeprecated`,
images.`deprecation_reason` AS `ImageDeprecationReason`,
images.`modified` AS `ModifiedTime`
FROM
Images images
INNER JOIN
Repositories repos ON repos.`id` = images.`repository`
WHERE
images.`repository` = in_repository
ORDER BY
images.`name` ASC;

END;
//

DELIMITER ;
2 changes: 2 additions & 0 deletions src/main/resources/spark/template/freemarker/base.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
</div>
</nav>

<div class="fleet-notifications"></div>

<#nested>

<footer class="text-center my-5">
Expand Down

0 comments on commit c100aad

Please sign in to comment.