[Scada-LTS] The possibility to add image sets without requiring a reboot
[Scada-LTS] The possibility to add image sets without a restart
- The Function for the system administrator.
Before the changes, the ScadaLTS program loaded images information once at startup and it was stored in memory for the entire duration of the program.
At the moment the administrator can add a picture to the resources by copying it to the appropriate directory and refresh cache images.
▶️ DTube
▶️ IPFS
How was it implemented?
I added: REST API - GET "/api/resources/imagesRefresh"
@Controller
public class ResourcesAPI {
private static final Log LOG = LogFactory.getLog(ResourcesAPI.class);
@Resource
private ResourcesService resourcesService;
@RequestMapping(value = "/api/resources/imagesRefresh", method = RequestMethod.GET)
public ResponseEntity<String> imagesRefresh(HttpServletRequest request) {
LOG.info("/api/resources/imagesRefresh");
try {
User user = Common.getUser(request);
if (user != null && user.isAdmin()) {
resourcesService.refreshImages();
return new ResponseEntity<String>(HttpStatus.OK);
} else {
return new ResponseEntity<String>(HttpStatus.UNAUTHORIZED);
}
} catch (Exception e) {
return new ResponseEntity<String>(e.toString(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
I added the service:
@Service
public class ResourcesService {
public void refreshImages() {
ViewGraphicLoader loader = new ViewGraphicLoader();
List<ImageSet> imageSets = new ArrayList<ImageSet>();
List<DynamicImage> dynamicImages = new ArrayList<DynamicImage>();
ServletContext ctx = Common.ctx.getCtx();
for (ViewGraphic g : loader.loadViewGraphics(ctx.getRealPath(""))) {
if (g.isImageSet())
imageSets.add((ImageSet) g);
else if (g.isDynamicImage())
dynamicImages.add((DynamicImage) g);
else
throw new ShouldNeverHappenException(
"Unknown view graphic type");
}
ctx.setAttribute(Common.ContextKeys.IMAGE_SETS, imageSets);
ctx.setAttribute(Common.ContextKeys.DYNAMIC_IMAGES, dynamicImages);
Common.ctx = new ContextWrapper(ctx);
}
}
I added a button in the System Settings tab.
<div class="borderDiv marB marR" style="float:left">
<table width="100%">
<tr>
<td>
<span class="smallTitle">Cache images</span>
</td>
</tr>
<tr>
<td>
<button onClick="refreshImages()">Refresh</button>
</td>
</tr>
</table>
</div>
I added function refreshImages on a button click
function refreshImages() {
var pathArray = location.href.split( '/' );
var protocol = pathArray[0];
var host = pathArray[2];
var appScada = pathArray[3];
var myLocation;
if (!myLocation) {
myLocation = protocol + "//" + host + "/" + appScada + "/";
}
jQuery.ajax({
type: 'GET',
dataType: 'text',
url:myLocation+"/api/resources/imagesRefresh",
success: function(msg){
alert("Success: the resource images has been refreshed");
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("Problem when refreshing assets:"+errorThrown.message);
}
});
}
The changes will be made in the release v0.0.9.4, which is planned the next week.
Pull request: 516
Thank you.
Posted on Utopian.io - Rewarding Open Source Contributors
Hey @grzesiekb I am @utopian-io. I have just upvoted you!
Achievements
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Congratulations @grzesiekb! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Award for the number of upvotes
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP
Do not miss the last announcement from @steemitboard!
Congratulations @grzesiekb! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Award for the number of upvotes
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP
Congratulations @grzesiekb! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Award for the number of upvotes
Click on any badge to view your Board of Honor.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP
Do not miss the last announcement from @steemitboard!
Congratulations @grzesiekb! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Award for the number of upvotes
Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word
STOP
Do not miss the last post from @steemitboard!
Participate in the SteemitBoard World Cup Contest!
Collect World Cup badges and win free SBD
Support the Gold Sponsors of the contest: @good-karma and @lukestokes