2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
19 define("archiva/admin/repository/maven2/repositories",["jquery","i18n","jquery.tmpl","bootstrap","jquery.validate","knockout","knockout.simpleGrid"],
20 function(jquery,i18n,jqueryTmpl,bootstrap,jqueryValidate,ko) {
22 // FIXME this must be dynamic if we do a plugin mechanism with dynamic repositories types
25 ManagedRepositoryType=function(type,label){
30 window.managedRepositoryTypes = [
31 new ManagedRepositoryType("default","Maven 2.x Repository")
34 ManagedRepository=function(id,name,layout,indexDirectory,location,snapshots,releases,blockRedeployments,cronExpression,
35 scanned,retentionPeriod,retentionCount,deleteReleasedSnapshots,stageRepoNeeded,description,
36 skipPackedIndexCreation,feedsUrl,url){
41 this.id=ko.observable(id);
42 this.id.subscribe(function(newValue){self.modified(true)});
44 //private String name;
45 this.name=ko.observable(name);
46 this.name.subscribe(function(newValue){self.modified(true)});
48 //private String layout = "default";
49 this.layout=ko.observable(layout);
50 this.layout.subscribe(function(newValue){self.modified(true)});
52 //private String indexDirectory;
53 this.indexDirectory=ko.observable(indexDirectory);
54 this.indexDirectory.subscribe(function(newValue){self.modified(true)});
56 //private String location;
57 this.location=ko.observable(location);
58 this.location.subscribe(function(newValue){self.modified(true)});
60 //private String cronExpression = "0 0 * * * ?";
61 this.cronExpression=ko.observable(cronExpression);
62 this.cronExpression.subscribe(function(newValue){self.modified(true)});
64 //private ManagedRepository stagingRepository;
66 //private int retentionPeriod = 100;
67 this.retentionPeriod=ko.observable(retentionPeriod);
68 this.retentionPeriod.subscribe(function(newValue){self.modified(true)});
70 //private int retentionCount = 2;
71 this.retentionCount=ko.observable(retentionCount);
72 this.retentionCount.subscribe(function(newValue){self.modified(true)});
74 //private boolean scanned = true;
75 this.scanned=ko.observable(scanned?scanned:true);
76 this.scanned.subscribe(function(newValue){self.modified(true)});
78 //private boolean deleteReleasedSnapshots;
79 this.deleteReleasedSnapshots=ko.observable(deleteReleasedSnapshots);
80 this.deleteReleasedSnapshots.subscribe(function(newValue){self.modified(true)});
82 //private boolean stageRepoNeeded;
83 this.stageRepoNeeded=ko.observable(stageRepoNeeded);
84 this.stageRepoNeeded.subscribe(function(newValue){self.modified(true)});
86 //private boolean snapshots = false;
87 this.snapshots=ko.observable(snapshots?snapshots:false);
88 this.snapshots.subscribe(function(newValue){self.modified(true)});
90 //private boolean releases = true;
91 this.releases=ko.observable(releases?releases:false);
92 this.releases.subscribe(function(newValue){self.modified(true)});
94 //private boolean blockRedeployments = false;
95 this.blockRedeployments=ko.observable(blockRedeployments?blockRedeployments:false);
96 this.blockRedeployments.subscribe(function(newValue){self.modified(true)});
98 //private String name;
99 this.description=ko.observable(description);
100 this.description.subscribe(function(newValue){self.modified(true)});
102 this.skipPackedIndexCreation=ko.observable(skipPackedIndexCreation?skipPackedIndexCreation:false);
103 this.skipPackedIndexCreation.subscribe(function(newValue){self.modified(true)});
105 this.feedsUrl=feedsUrl;
109 this.getTypeLabel=function(){
110 for(var i=0;i<window.managedRepositoryTypes.length;i++){
111 if (window.managedRepositoryTypes[i].type==self.layout()){
112 return window.managedRepositoryTypes[i].label;
118 this.modified=ko.observable(false);
121 ArchivaRepositoryStatistics=function(scanEndTime,scanStartTime,totalArtifactCount,totalArtifactFileSize,totalFileCount,
122 totalGroupCount,totalProjectCount,newFileCount,duration,managedRepository,lastScanDate){
123 //private Date scanEndTime;
124 this.scanEndTime = ko.observable(scanEndTime);
126 //private Date scanStartTime;
127 this.scanStartTime = ko.observable(scanStartTime);
129 //private long totalArtifactCount;
130 this.totalArtifactCount = ko.observable(totalArtifactCount);
132 //private long totalArtifactFileSize;
133 this.totalArtifactFileSize = ko.observable(totalArtifactFileSize);
135 //private long totalFileCount;
136 this.totalFileCount = ko.observable(totalFileCount);
138 //private long totalGroupCount;
139 this.totalGroupCount = ko.observable(totalGroupCount);
141 //private long totalProjectCount;
142 this.totalProjectCount = ko.observable(totalProjectCount);
144 //private long newFileCount;
145 this.newFileCount = ko.observable(newFileCount);
147 this.duration = ko.observable(duration);
149 this.managedRepository = managedRepository;
151 this.lastScanDate=ko.observable(lastScanDate);
154 mapManagedRepositories=function(data,applicationUrl){
155 var mappedManagedRepositories = $.map(data, function(item) {
156 var managedRepository = mapManagedRepository(item);
157 managedRepository.feedsUrl=applicationUrl+"/feeds/"+managedRepository.id();
158 managedRepository.url=applicationUrl+"/repository/"+managedRepository.id()
159 return managedRepository;
161 return mappedManagedRepositories;
163 mapManagedRepository=function(data){
167 return new ManagedRepository(data.id,data.name,data.layout,data.indexDirectory,data.location,data.snapshots
169 data.blockRedeployments,data.cronExpression,
170 data.scanned,data.retentionPeriod,data.retentionCount,data.deleteReleasedSnapshots,
171 data.stageRepoNeeded,data.description,data.skipPackedIndexCreation);
174 mapArchivaRepositoryStatistics=function(data){
178 return new ArchivaRepositoryStatistics(data.scanEndTime,data.scanStartTime,data.totalArtifactCount,data.totalArtifactFileSize,
179 data.totalFileCount,data.totalGroupCount,data.totalProjectCount,data.newFileCount,
180 data.duration,data.managedRepository,data.lastScanDate)
183 ManagedRepositoryViewModel=function(managedRepository, update, managedRepositoriesViewModel){
184 this.managedRepository=managedRepository;
185 this.managedRepositoriesViewModel = managedRepositoriesViewModel;
186 this.update = update;
190 this.availableLayouts = window.managedRepositoryTypes;
192 showCronExpressionDoc=function(){
193 //$.log("showCronExpressionDoc") ;
196 this.save=function(){
197 $.log('managedrepo save');
198 var valid = $("#main-content").find("#managed-repository-edit-form").valid();
202 $.log("save:"+this.managedRepository.name());
204 var userMessages=$("#user-messages");
205 userMessages.html(mediumSpinnerImg());
206 $("#managed-repository-save-button" ).button('loading');
208 $.ajax("restServices/archivaServices/managedRepositoriesService/updateManagedRepository",
211 data: ko.toJSON(this.managedRepository),
212 contentType: 'application/json',
214 success: function(data) {
215 displaySuccessMessage($.i18n.prop('managedrepository.updated',self.managedRepository.id()));
216 activateManagedRepositoriesGridTab();
217 self.managedRepository.modified(false);
219 complete: function(){
220 $("#managed-repository-save-button" ).button('reset');
221 removeMediumSpinnerImg(userMessages);
226 var url="restServices/archivaServices/managedRepositoriesService/fileLocationExists";
227 url+="?fileLocation="+encodeURIComponent(self.managedRepository.location());
232 success: function(data) {
234 var completeCallbackFn = function(){window.modalConfirmDialog.modal('hide')};
236 function(){addManagedRepository(self.managedRepository,completeCallbackFn)},
237 $.i18n.prop('ok'), $.i18n.prop('cancel'),
238 $.i18n.prop('managedrepository.add.title'),
239 $("#managed-repository-location-warning-tmpl").tmpl(self.managedRepository));
241 addManagedRepository(self.managedRepository);
244 complete: function(){
245 $("#managed-repository-save-button" ).button('reset');
246 removeMediumSpinnerImg(userMessages);
252 addManagedRepository=function(managedRepository,completeCallbackFn){
253 var curManagedRepository=managedRepository;
254 var callbackFn = completeCallbackFn;
255 var dataJson=ko.toJSON(managedRepository);
256 $.log("managedRepository.release:"+managedRepository.releases()+",dataJson:"+dataJson);
257 $.ajax("restServices/archivaServices/managedRepositoriesService/addManagedRepository",
260 contentType: 'application/json',
263 success: function(data) {
264 if (managedRepository.stageRepoNeeded()){
265 $.log("stageRepoNeeded:"+managedRepository.stageRepoNeeded());
266 // reload all to see the new staged repo
267 loadManagedRepositories(function(data){
268 self.managedRepositoriesViewModel.managedRepositories(mapManagedRepositories(data));
271 curManagedRepository.location(data.location);
272 self.managedRepositoriesViewModel.managedRepositories.push(curManagedRepository);
275 displaySuccessMessage($.i18n.prop('managedrepository.added',curManagedRepository.id()));
276 curManagedRepository.modified(false);
277 activateManagedRepositoriesGridTab();
279 error: function(data) {
280 var res = $.parseJSON(data.responseText);
281 displayRestError(res);
283 complete:function(data){
292 displayGrid=function(){
293 activateManagedRepositoriesGridTab();
298 activateManagedRepositoryFormValidation=function(){
299 var validator = $("#main-content" ).find("#managed-repository-edit-form").validate({
313 url: "restServices/archivaServices/commonServices/validateCronExpression",
320 url: "restServices/archivaUiServices/dataValidatorService/managedRepositoryIdNotExists",
325 showErrors: function(validator, errorMap, errorList) {
326 customShowError("#main-content #managed-repository-edit-form",validator,errorMap,errorMap);
329 validator.settings.messages["cronExpression"]=$.i18n.prop("cronExpression.notvalid");
330 validator.settings.messages["id"]=$.i18n.prop("id.required.or.alreadyexists");
333 ManagedRepositoriesViewModel=function(){
334 this.managedRepositories=ko.observableArray([]);
336 this.gridViewModel = null;
339 editManagedRepository=function(managedRepository){
340 var mainContent = $("#main-content");
341 var viewModel = new ManagedRepositoryViewModel(managedRepository,true,self);
342 ko.applyBindings(viewModel,mainContent.find("#managed-repository-edit").get(0));
343 activateManagedRepositoryEditTab();
344 mainContent.find("#managed-repository-edit-li a").html($.i18n.prop('edit'));
345 activateManagedRepositoryFormValidation();
346 activatePopoverDoc();
349 this.editManagedRepositoryWithId=function(managedRepositoryId){
350 $.each(self.managedRepositories(), function(index, value) {
351 if(value.id()==managedRepositoryId){
352 editManagedRepository(value);
357 scanNow=function(managedRepository){
361 $("#dialog-confirm-modal" ).find("#modal-login-footer").append(smallSpinnerImg());
362 var checked = $("#managed-repository-scan-now-all").get(0).checked;
363 var url = "restServices/archivaServices/repositoriesService/scanRepositoryNow?";
364 url += "repositoryId="+encodeURIComponent(managedRepository.id());
365 url += "&fullScan="+(checked==true?"true":"false");
369 beforeSend:function(){
370 displayInfoMessage($.i18n.prop("managedrepository.scan.started",managedRepository.id()));
371 closeDialogConfirm();
373 success: function(data) {
374 displaySuccessMessage($.i18n.prop("managedrepository.scanned",managedRepository.name()));
376 error: function(data) {
377 var res = $.parseJSON(data.responseText);
378 displayRestError(res);
380 complete: function(){
381 removeSmallSpinnerImg();
382 closeDialogConfirm();
388 $.i18n.prop("cancel"),
389 $.i18n.prop("managedrepository.scan.now"),
390 $("#managed-repository-scan-now-modal-tmpl").tmpl(managedRepository));
394 removeManagedRepository=function(managedRepository){
398 var url = "restServices/archivaServices/managedRepositoriesService/deleteManagedRepository?";
399 url += "repositoryId="+encodeURIComponent(managedRepository.id());
400 var checked = $("#managedrepository-deletecontent").get(0).checked;
401 url += "&deleteContent="+(checked==true?"true":"false");
402 var dialogText=$("#dialog-confirm-modal-body-text" );
403 dialogText.html(mediumSpinnerImg());
407 success: function(data) {
408 self.managedRepositories.remove(managedRepository);
409 displaySuccessMessage($.i18n.prop("managedrepository.deleted",managedRepository.name()));
412 error: function(data) {
413 var res = $.parseJSON(data.responseText);
414 displayRestError(res);
416 complete: function(){
417 removeMediumSpinnerImg(dialogText);
418 closeDialogConfirm();
425 $.i18n.prop("cancel"),
426 $.i18n.prop("managedrepository.delete.confirm",managedRepository.name()),
427 $("#managed-repository-delete-warning-tmpl").tmpl(managedRepository));
430 updateManagedRepository=function(managedRepository){
431 var managedRepositoryViewModel = new ManagedRepositoryViewModel(managedRepository,true,this);
432 managedRepositoryViewModel.save();
435 this.bulkSave=function(){
437 return getModifiedManagedRepositories().length>0;
440 getModifiedManagedRepositories=function(){
441 var prx = $.grep(self.managedRepositories(),
442 function (managedRepository,i) {
443 return managedRepository.modified();
447 updateModifiedManagedRepositories=function(){
448 var repos = getModifiedManagedRepositories();
450 openDialogConfirm(function(){
451 for (i=0;i<repos.length;i++){
452 updateManagedRepository(repos[i]);
454 closeDialogConfirm();
457 $.i18n.prop('cancel'),
458 $.i18n.prop('managed.repository.bulk.save.confirm.title'),
459 $.i18n.prop('managed.repository.bulk.save.confirm',repos.length));
462 directoriesScan=function(managedRepository){
463 $.log("directoriesScan:"+managedRepository.id());
465 var url = "restServices/archivaServices/repositoriesService/scanRepositoryDirectoriesNow/"+managedRepository.id();
470 beforeSend:function(){
471 displayInfoMessage($.i18n.prop("managedrepository.scan.directories.started", managedRepository.id()));
473 success: function(data) {
474 $.log(" scanRepositoryDirectoriesNow finished ");
475 displaySuccessMessage( $.i18n.prop("managedrepository.scan.directories.finished", managedRepository.id()));
477 error: function(data) {
478 var res = $.parseJSON(data.responseText);
479 displayRestError(res);
481 complete: function(){
482 removeSmallSpinnerImg();
489 showStats=function(managedRepository){
490 if ($(calculatePopoverId(managedRepository)).html()){
491 // we ask stats all the time ? if no uncomment return
493 $("#managedrepository-stats-"+escapeDot(managedRepository.id())).append(smallSpinnerImg());
495 var curRepo=managedRepository;
496 var url = "restServices/archivaServices/managedRepositoriesService/getManagedRepositoryStatistics/"+managedRepository.id();
497 url+="/"+encodeURIComponent(usedLang());
502 success: function(data) {
506 var archivaRepositoryStatistics=mapArchivaRepositoryStatistics(data);
507 archivaRepositoryStatistics.managedRepository=curRepo;
508 var mainContent = $("#main-content");
509 mainContent.find("#managedrepository-stats-"+escapeDot(curRepo.id())).append($("#managed-repository-stats-tmpl").tmpl(archivaRepositoryStatistics));
510 mainContent.find("#managedrepository-stats-img-"+escapeDot(curRepo.id())).attr("data-content",$(calculatePopoverId(curRepo)).html());
511 mainContent.find("#managedrepository-stats-img-"+escapeDot(curRepo.id())).popover(
519 mainContent.find("#managedrepository-stats-img-"+escapeDot(curRepo.id())).popover('show');
520 removeSmallSpinnerImg();
522 error: function(data) {
523 var res = $.parseJSON(data.responseText);
524 displayRestError(res);
526 complete: function(){
532 calculatePopoverId=function(managedRepository){
533 return "#main-content #managedrepository-stats-"+escapeDot(managedRepository.id()) + " #managedrepository-stats-"+escapeDot(managedRepository.id())+"-popover";
536 hideStats=function(managedRepository){
537 $("#body_content" ).find(".popover" ).hide();
540 showPomSnippet=function(managedRepository){
541 var mainContent = $("#main-content");
542 mainContent.find("#managed-repositories-pom-snippet").html(mediumSpinnerImg());
543 mainContent.find('#managed-repositories-pom-snippet').show();
544 var url = "restServices/archivaServices/managedRepositoriesService/getPomSnippet/"+encodeURIComponent(managedRepository.id());
549 success: function(data) {
550 $("#managed-repositories-pom-snippet").html($("#pom-snippet-tmpl").tmpl(data));
552 error: function(data) {
553 var res = $.parseJSON(data.responseText);
554 displayRestError(res);
556 complete: function(){
563 mergeRepo=function(managedRepository){
564 var userMessages=$("#user-messages");
565 userMessages.html(mediumSpinnerImg());
566 // is there any artifacts to merge ?
567 var artifactsNumberUrl = "restServices/archivaServices/browseService/artifacts/"+encodeURIComponent(managedRepository.id());
568 $.ajax(artifactsNumberUrl,{
571 success: function(data){
572 var artifacts=mapArtifacts(data);
573 $.log("artifactsNumber for '" + managedRepository.id() + "': " + artifacts.length);
576 displayWarningMessage($.i18n.prop("managedrepository.merge.noartifacts", managedRepository.id()));
580 $.log("merge repo open dialog");
581 var dialogMergeRepo=$("#dialog-modal-merge-repo");
582 if (window.modalMergeRepoDialog==null) {
583 window.modalMergeRepoDialog = dialogMergeRepo.modal();
587 loadManagedRepositories(function(data){
589 var managedRepositories = $.map(mapManagedRepositories(data), function(item) {
590 return item.id()==managedRepository.id()?null:item;
592 $("#dialog-modal-merge-repo-body-text").html($("#merge-repo-dialog-content" )
593 .tmpl({sourceRepoId:managedRepository.id(),repositories:managedRepositories}));
594 window.modalMergeRepoDialog.modal('show');
598 complete: function(){
599 removeMediumSpinnerImg(userMessages);
610 mergeRepositories=function(sourceRepository,targetRepository){
611 $.log("mergeRepositories:"+sourceRepository+":"+targetRepository);
613 var mergeRepoDialogBodyId="dialog-modal-merge-repo-body-text";
614 var mergeRepoDialogBody=$("#"+mergeRepoDialogBodyId);
615 mergeRepoDialogBody.html(mediumSpinnerImg());
618 var url = "restServices/archivaServices/mergeRepositoriesService/mergeConflictedArtifacts/"+encodeURIComponent(sourceRepository);
619 url+="/"+encodeURIComponent(targetRepository);
623 success: function(data){
624 var artifacts=mapArtifacts(data);
625 if (artifacts && artifacts.length){
626 // we have conflicts ask to skip or not
627 $.log("conflicts:"+artifacts.length);
628 displayWarningMessage($.i18n.prop("managedrepository.merge.conflicts", artifacts.length),"dialog-modal-merge-repo-body-text");
629 $.tmpl($("#merge-repo-skip-conflicts").html(),
630 { artifacts:artifacts, sourceRepository: sourceRepository, targetRepository:targetRepository })
631 .appendTo( "#dialog-modal-merge-repo-body-text" );
632 $("#dialog-modal-merge-repo-header-title" ).html($.i18n.prop("managedrepository.merge.conflicts.header",sourceRepository,targetRepository));
634 doMerge(sourceRepository,targetRepository,false);
637 complete: function(){
638 $.log("complete removeMediumSpinnerImg");
639 removeMediumSpinnerImg("#dialog-modal-merge-repo-body-text");
647 doMerge=function(sourceRepository,targetRepository,skipConflicts){
648 $.log("doMerge:"+sourceRepository+" to " + targetRepository + ", skipConflicts: " + skipConflicts);
649 window.modalMergeRepoDialog.modal('hide');
650 var userMessages=$("#user-messages");
651 userMessages.html(mediumSpinnerImg());
652 var url = "restServices/archivaServices/mergeRepositoriesService/mergeRepositories/"+encodeURIComponent(sourceRepository);
653 url+="/"+encodeURIComponent(targetRepository);
654 url+="/"+skipConflicts;
658 success: function(data){
659 displaySuccessMessage($.i18n.prop("managedrepository.merge.success", sourceRepository,targetRepository));
661 complete: function(){
662 removeMediumSpinnerImg(userMessages);
667 activateManagedRepositoriesGridTab=function(){
668 var mainContent = $("#main-content");
669 mainContent.find("#managed-repository-edit-li").removeClass("active");
670 mainContent.find("#managed-repository-edit").removeClass("active");
672 mainContent.find("#managed-repositories-view-li").addClass("active");
673 mainContent.find("#managed-repositories-view").addClass("active");
674 mainContent.find("#managed-repository-edit-li a").html($.i18n.prop("add"));
677 activateManagedRepositoryEditTab=function(){
678 var mainContent = $("#main-content");
679 mainContent.find("#managed-repositories-view-li").removeClass("active");
680 mainContent.find("#managed-repositories-view").removeClass("active");
682 mainContent.find("#managed-repository-edit-li").addClass("active");
683 mainContent.find("#managed-repository-edit").addClass("active");
687 //---------------------------
688 // Remote repositories part
689 //---------------------------
693 RemoteRepository=function(id,name,layout,indexDirectory,url,userName,password,timeout,downloadRemoteIndex,remoteIndexUrl,
694 remoteDownloadNetworkProxyId,cronExpression,remoteDownloadTimeout,downloadRemoteIndexOnStartup,
695 description,extraParametersEntries,extraHeadersEntries,checkPath){
700 this.id=ko.observable(id);
701 this.id.subscribe(function(newValue){self.modified(true)});
703 //private String name;
704 this.name=ko.observable(name);
705 this.name.subscribe(function(newValue){self.modified(true)});
707 //private String layout = "default";
708 this.layout=ko.observable(layout);
709 this.layout.subscribe(function(newValue){self.modified(true)});
711 //private String indexDirectory;
712 this.indexDirectory=ko.observable(indexDirectory);
713 this.indexDirectory.subscribe(function(newValue){self.modified(true)});
715 //private String url;
716 this.url=ko.observable(url);
717 this.url.subscribe(function(newValue){self.modified(true)});
719 //private String userName;
720 this.userName=ko.observable(userName);
721 this.userName.subscribe(function(newValue){self.modified(true)});
723 //private String password;
724 this.password=ko.observable(password);
725 this.password.subscribe(function(newValue){self.modified(true)});
727 //private int timeout = 60;
728 this.timeout=ko.observable(timeout);
729 this.timeout.subscribe(function(newValue){self.modified(true)});
731 //private boolean downloadRemoteIndex = false;
732 this.downloadRemoteIndex=ko.observable(downloadRemoteIndex?false:downloadRemoteIndex);
733 this.downloadRemoteIndex.subscribe(function(newValue){self.modified(true)});
735 //private String remoteIndexUrl = ".index";
736 this.remoteIndexUrl=ko.observable(remoteIndexUrl);
737 this.remoteIndexUrl.subscribe(function(newValue){self.modified(true)});
739 //private String remoteDownloadNetworkProxyId;
740 this.remoteDownloadNetworkProxyId=ko.observable(remoteDownloadNetworkProxyId);
741 this.remoteDownloadNetworkProxyId.subscribe(function(newValue){self.modified(true)});
743 //private String cronExpression = "0 0 08 ? * SUN";
744 this.cronExpression=ko.observable(cronExpression);
745 this.cronExpression.subscribe(function(newValue){self.modified(true)});
747 //private int remoteDownloadTimeout = 300;
748 this.remoteDownloadTimeout=ko.observable(remoteDownloadTimeout);
749 this.remoteDownloadTimeout.subscribe(function(newValue){self.modified(true)});
751 //private boolean downloadRemoteIndexOnStartup = false;
752 this.downloadRemoteIndexOnStartup=ko.observable(downloadRemoteIndexOnStartup?false:downloadRemoteIndexOnStartup);
753 this.downloadRemoteIndexOnStartup.subscribe(function(newValue){self.modified(true)});
755 this.description=ko.observable(description);
756 this.description.subscribe(function(newValue){self.modified(true)});
758 this.getTypeLabel=function(){
759 for(var i=0;i<window.managedRepositoryTypes.length;i++){
760 if (window.managedRepositoryTypes[i].type==self.layout()){
761 return window.managedRepositoryTypes[i].label;
767 this.extraParametersEntries=ko.observableArray(extraParametersEntries==null?new Array():extraParametersEntries);
768 this.extraParametersEntries.subscribe(function(newValue){
772 this.extraHeadersEntries=ko.observableArray(extraHeadersEntries==null?new Array():extraHeadersEntries);
773 this.extraHeadersEntries.subscribe(function(newValue){
777 this.checkPath=ko.observable(checkPath);
778 this.checkPath.subscribe(function(newValue){self.modified(true)});
780 this.modified=ko.observable(false);
783 mapRemoteRepository=function(data){
788 var extraParametersEntries = data.extraParametersEntries == null ? []: $.each(data.extraParametersEntries,function(item){
789 return new Entry(item.key, item.value);
791 if (!$.isArray(extraParametersEntries)){
792 extraParametersEntries=[];
795 var extraHeadersEntries = data.extraHeadersEntries == null ? []: $.each(data.extraHeadersEntries,function(item){
796 return new Entry(item.key, item.value);
798 if (!$.isArray(extraHeadersEntries)){
799 extraHeadersEntries=[];
802 return new RemoteRepository(data.id,data.name,data.layout,data.indexDirectory,data.url,data.userName,data.password,
803 data.timeout,data.downloadRemoteIndex,data.remoteIndexUrl,data.remoteDownloadNetworkProxyId,
804 data.cronExpression,data.remoteDownloadTimeout,data.downloadRemoteIndexOnStartup,data.description,
805 extraParametersEntries,extraHeadersEntries,data.checkPath);
808 mapRemoteRepositories=function(data){
809 var mappedRemoteRepositories = $.map(data, function(item) {
810 return mapRemoteRepository(item);
812 return mappedRemoteRepositories;
815 RemoteRepositoryViewModel=function(remoteRepository, update, remoteRepositoriesViewModel){
816 this.remoteRepository=remoteRepository;
817 this.remoteRepositoriesViewModel = remoteRepositoriesViewModel;
818 this.networkProxies=ko.observableArray([]);
819 this.update = update;
823 this.availableLayouts = window.managedRepositoryTypes;
825 this.save=function(){
826 var valid = $("#main-content" ).find("#remote-repository-edit-form").valid();
831 var userMessages=$("#user-messages");
832 userMessages.html(mediumSpinnerImg());
833 $("#remote-repository-save-button" ).button('loading');
835 $.ajax("restServices/archivaServices/remoteRepositoriesService/updateRemoteRepository",
838 data: ko.toJSON(this.remoteRepository),
839 contentType: 'application/json',
841 success: function(data) {
842 displaySuccessMessage($.i18n.prop('remoterepository.updated',self.remoteRepository.id()));
843 activateRemoteRepositoriesGridTab();
844 self.remoteRepository.modified(false);
846 error: function(data) {
847 var res = $.parseJSON(data.responseText);
848 displayRestError(res);
850 complete: function(){
851 $("#remote-repository-save-button" ).button('reset');
852 removeMediumSpinnerImg(userMessages);
857 $.ajax("restServices/archivaServices/remoteRepositoriesService/addRemoteRepository",
860 data: ko.toJSON(this.remoteRepository),
861 contentType: 'application/json',
863 success: function(data) {
864 self.remoteRepository.modified(false);
865 self.remoteRepositoriesViewModel.remoteRepositories.push(self.remoteRepository);
866 displaySuccessMessage($.i18n.prop('remoterepository.added'));
867 activateRemoteRepositoriesGridTab();
868 removeMediumSpinnerImg(userMessages);
870 error: function(data) {
871 var res = $.parseJSON(data.responseText);
872 displayRestError(res);
879 displayGrid=function(){
880 activateRemoteRepositoriesGridTab();
883 addExtraParameter=function(){
885 var mainContent=$("#main-content");
886 mainContent.find("#extra-parameters-error" ).empty();
887 var key=mainContent.find("#extraParameter-key").val();
888 if($.trim(key).length<1){
889 displayErrorMessage( $.i18n.prop("key.empty.error.message"),"extra-parameters-error");
892 var value=mainContent.find("#extraParameter-value").val();
893 $.log("addExtraParameter="+key+":"+value);
894 var oldTab = self.remoteRepository.extraParametersEntries();
895 oldTab.push(new Entry(key,value));
896 self.remoteRepository.extraParametersEntries(oldTab);
897 mainContent.find("#extraParameter-key").val("");
898 mainContent.find("#extraParameter-value").val("");
899 self.remoteRepository.modified(true);
902 deleteExtraParameter=function(key){
903 for(var i=0;i<self.remoteRepository.extraParametersEntries().length;i++){
904 var entry=self.remoteRepository.extraParametersEntries()[i];
906 self.remoteRepository.extraParametersEntries.remove(entry);
907 self.remoteRepository.modified(true);
912 addExtraHeader=function(){
914 var mainContent=$("#main-content");
915 mainContent.find("#extra-headers-error" ).empty();
916 var key=mainContent.find("#extraHeader-key").val();
917 if( $.trim(key).length<1){
918 if($.trim(key).length<1){
919 displayErrorMessage( $.i18n.prop("key.empty.error.message"),"extra-headers-error");
923 var value=mainContent.find("#extraHeader-value").val();
924 $.log("addExtraParameter="+key+":"+value);
925 var oldTab = self.remoteRepository.extraHeadersEntries();
926 oldTab.push(new Entry(key,value));
927 self.remoteRepository.extraHeadersEntries(oldTab);
928 mainContent.find("#extraHeader-key").val("");
929 mainContent.find("#extraHeader-value").val("");
930 self.remoteRepository.modified(true);
933 deleteExtraHeader=function(key){
934 for(var i=0;i<self.remoteRepository.extraHeadersEntries().length;i++){
935 var entry=self.remoteRepository.extraHeadersEntries()[i];
937 self.remoteRepository.extraHeadersEntries.remove(entry);
938 self.remoteRepository.modified(true);
945 RemoteRepositoriesViewModel=function(){
946 this.remoteRepositories=ko.observableArray([]);
947 this.applicationUrl=null;
948 this.gridViewModel = null;
951 editRemoteRepository=function(remoteRepository){
952 $.log("editRemoteRepository");
953 $.ajax("restServices/archivaServices/networkProxyService/getNetworkProxies", {
956 success: function(data) {
957 var viewModel = new RemoteRepositoryViewModel(remoteRepository,true,self);
958 viewModel.networkProxies(mapNetworkProxies(data));
959 var mainContent = $("#main-content");
961 ko.applyBindings(viewModel,mainContent.find("#remote-repository-edit").get(0));
962 activateRemoteRepositoryEditTab();
963 mainContent.find("#remote-repository-edit-li a").html($.i18n.prop('edit'));
964 activateRemoteRepositoryFormValidation(false);
965 activatePopoverDoc();
971 removeRemoteRepository=function(remoteRepository){
975 var dialogText=$("#dialog-confirm-modal-body-text" );
976 dialogText.html(mediumSpinnerImg());
977 $.ajax("restServices/archivaServices/remoteRepositoriesService/deleteRemoteRepository/"+encodeURIComponent(remoteRepository.id()),
980 success: function(data) {
981 self.remoteRepositories.remove(remoteRepository);
982 displaySuccessMessage($.i18n.prop('remoterepository.deleted',remoteRepository.id()));
984 error: function(data) {
985 var res = $.parseJSON(data.responseText);
986 displayRestError(res);
989 removeMediumSpinnerImg(dialogText);
990 closeDialogConfirm();
993 )}, $.i18n.prop('ok'),
994 $.i18n.prop('cancel'),
995 $.i18n.prop('remoterepository.delete.confirm',remoteRepository.id()),
996 $("#remote-repository-delete-modal-tmpl").tmpl(remoteRepository));
1000 this.bulkSave=function(){
1001 return getModifiedRemoteRepositories().length>0;
1004 getModifiedRemoteRepositories=function(){
1005 var prx = $.grep(self.remoteRepositories(),
1006 function (remoteRepository,i) {
1007 return remoteRepository.modified();
1012 updateModifiedRemoteRepositories=function(){
1013 var modifiedRemoteRepositories = getModifiedRemoteRepositories();
1015 openDialogConfirm(function(){
1016 for(var i=0;i<modifiedRemoteRepositories.length;i++){
1017 updateRemoteRepository(modifiedRemoteRepositories[i]);
1019 closeDialogConfirm();
1022 $.i18n.prop('cancel'),
1023 $.i18n.prop('remoterepositories.bulk.save.confirm.title'),
1024 $.i18n.prop('remoterepositories.bulk.save.confirm',modifiedRemoteRepositories.length));
1027 updateRemoteRepository=function(remoteRepository){
1028 var viewModel = new RemoteRepositoryViewModel(remoteRepository,true,self);
1032 scheduleDownloadRemoteIndex=function(remoteRepository){
1036 var url = "restServices/archivaServices/repositoriesService/scheduleDownloadRemoteIndex?";
1037 url += "repositoryId="+encodeURIComponent(remoteRepository.id());
1039 var now = $("#remoterepository-scan-now").get(0).checked;
1041 var full = $("#remoterepository-scan-full").get(0).checked;
1043 url += "&now="+(now==true?"true":"false");
1044 url += "&fullDownload="+(full==true?"true":"false");
1048 success: function(data) {
1049 clearUserMessages();
1050 displaySuccessMessage($.i18n.prop("remoterepository.download.remote.scheduled",remoteRepository.name()));
1052 error: function(data) {
1053 var res = $.parseJSON(data.responseText);
1054 displayRestError(res);
1056 complete: function(){
1057 closeDialogConfirm();
1064 $.i18n.prop("cancel"),
1065 $.i18n.prop("remoterepository.download.remote.confirm",remoteRepository.name()),
1066 $("#remote-repository-scan-modal-tmpl").tmpl(remoteRepository));
1072 * @param validateId to validate if id already exists: not needed for update !
1074 activateRemoteRepositoryFormValidation=function(validateId){
1075 // FIXME find a way to activate cronExpression validation only if downloadRemote is activated !
1076 var validator = null;
1078 validator = $("#main-content" ).find("#remote-repository-edit-form").validate({
1083 url: "restServices/archivaUiServices/dataValidatorService/remoteRepositoryIdNotExists",
1088 showErrors: function(validator, errorMap, errorList) {
1089 customShowError("#main-content #remote-repository-edit-form",validator,errorMap,errorMap);
1093 validator = $("#main-content" ).find("#remote-repository-edit-form").validate({
1099 showErrors: function(validator, errorMap, errorList) {
1100 customShowError("#main-content #remote-repository-edit-form",validator,errorMap,errorMap);
1104 validator.settings.messages["cronExpression"]=$.i18n.prop("cronExpression.notvalid");
1105 validator.settings.messages["id"]=$.i18n.prop("id.required.or.alreadyexists");
1108 activateRemoteRepositoriesGridTab=function(){
1109 var mainContent = $("#main-content");
1110 mainContent.find("#remote-repository-edit-li").removeClass("active");
1111 mainContent.find("#remote-repository-edit").removeClass("active");
1113 mainContent.find("#remote-repositories-view-li").addClass("active");
1114 mainContent.find("#remote-repositories-view").addClass("active");
1115 mainContent.find("#remote-repository-edit-li a").html($.i18n.prop("add"));
1118 activateRemoteRepositoryEditTab=function(){
1119 var mainContent = $("#main-content");
1120 mainContent.find("#remote-repositories-view-li").removeClass("active");
1121 mainContent.find("#remote-repositories-view").removeClass("active");
1123 mainContent.find("#remote-repository-edit-li").addClass("active");
1124 mainContent.find("#remote-repository-edit").addClass("active");
1127 //---------------------------
1129 //---------------------------
1133 * @param successFnManagedRepositories function called with param managedRepositoriesViewModel when managed repositories grid has been displayed
1134 * @param successFnRemoteRepositories function called with param remoteRepositoriesViewModel when remote repositories grid has been displayed
1136 displayRepositoriesGrid=function(successFnManagedRepositories,successFnRemoteRepositories){
1138 var mainContent = $("#main-content");
1139 mainContent.html(mediumSpinnerImg());
1140 mainContent.html($("#repositoriesMain").tmpl());
1141 mainContent.find("#repositories-tabs a:first").tab("show");
1143 mainContent.find("#managed-repositories-content").append(mediumSpinnerImg());
1144 mainContent.find("#remote-repositories-content").append(mediumSpinnerImg());
1146 var managedRepositoriesViewModel = new ManagedRepositoriesViewModel();
1147 var remoteRepositoriesViewModel = new RemoteRepositoriesViewModel();
1150 url: "restServices/archivaServices/archivaAdministrationService/applicationUrl",
1153 success: function(applicationUrl){
1154 $.log("applicationUrl:"+applicationUrl);
1155 loadManagedRepositories(function(data) {
1158 managedRepositoriesViewModel.managedRepositories(
1159 mapManagedRepositories(data,applicationUrl?applicationUrl:window.location.toString().substringBeforeLast("/")));
1161 managedRepositoriesViewModel.gridViewModel = new ko.simpleGrid.viewModel({
1162 data: managedRepositoriesViewModel.managedRepositories,
1165 headerText: $.i18n.prop('identifier'),
1169 headerText: $.i18n.prop('name'),
1173 headerText: $.i18n.prop('type'),
1174 rowText: "getTypeLabel",
1176 title: "Repository type (default is Maven 2)"
1180 gridUpdateCallBack: function(){
1182 //$("#main-content" ).find("#managed-repositories-table").find("[title]").tooltip({animation:"false"});
1185 var mainContent = $("#main-content");
1186 ko.applyBindings(managedRepositoriesViewModel,mainContent.find("#managed-repositories-view").get(0));
1187 activatePopoverDoc();
1188 mainContent.find("#managed-repositories-pills #managed-repositories-view-a").tab('show');
1189 removeMediumSpinnerImg(mainContent.find("#managed-repositories-content"));
1190 activateManagedRepositoriesGridTab();
1191 if(successFnManagedRepositories){
1192 successFnManagedRepositories(managedRepositoriesViewModel);
1196 loadRemoteRepositories(function(data) {
1197 remoteRepositoriesViewModel.remoteRepositories(mapRemoteRepositories(data));
1198 remoteRepositoriesViewModel.gridViewModel = new ko.simpleGrid.viewModel({
1199 data: remoteRepositoriesViewModel.remoteRepositories,
1202 headerText: $.i18n.prop('identifier'),
1206 headerText: $.i18n.prop('name'),
1210 headerText: $.i18n.prop('url'),
1214 headerText: $.i18n.prop('type'),
1215 rowText: "getTypeLabel",
1217 title: "Repository type (default is Maven 2)"
1221 gridUpdateCallBack: function(){
1222 $.log("remote repositories gridUpdateCallBack");
1225 mainContent.find(".remote-check").each(function( index ) {
1226 var repoId = $( this ).attr("id");
1227 console.log( index + ": " + repoId);
1229 url: "restServices/archivaServices/remoteRepositoriesService/checkRemoteConnectivity/"+repoId.substringAfterFirst("remote-check-"),
1232 success: function(result){
1233 $.log("result:"+result);
1235 mainContent.find("img[id='"+repoId+"']").attr("src", "images/weather-clear.png" );
1237 mainContent.find("img[id='"+repoId+"']").attr("src", "images/weather-severe-alert-16-16.png" );
1240 error: function(result){
1241 mainContent.find("img[id='"+repoId+"']").attr("src", "images/weather-severe-alert-16-16.png" );
1249 var mainContent = $("#main-content");
1250 ko.applyBindings(remoteRepositoriesViewModel,mainContent.find("#remote-repositories-view").get(0));
1251 mainContent.find("#remote-repositories-pills #remote-repositories-view-a").tab('show');
1252 removeMediumSpinnerImg(mainContent.find("#remote-repositories-content"));
1253 activatePopoverDoc();
1254 if(successFnRemoteRepositories){
1255 successFnRemoteRepositories(managedRepositoriesViewModel);
1263 mainContent.find("#managed-repositories-pills").on('show', function (e) {
1264 var mainContent = $("#main-content");
1265 if ($(e.target).attr("href")=="#managed-repository-edit") {
1266 var managedRepo=new ManagedRepository();
1267 managedRepo.cronExpression("0 0 * * * ?");
1268 var viewModel = new ManagedRepositoryViewModel(managedRepo,false,managedRepositoriesViewModel);
1269 ko.applyBindings(viewModel,mainContent.find("#managed-repository-edit").get(0));
1270 activateManagedRepositoryFormValidation();
1271 activatePopoverDoc();
1273 if ($(e.target).attr("href")=="#managed-repositories-view") {
1274 mainContent.find("#managed-repository-edit-li a").html($.i18n.prop("add"));
1279 mainContent.find("#remote-repositories-pills").on('show', function (e) {
1280 if ($(e.target).attr("href")=="#remote-repository-edit") {
1281 $.ajax("restServices/archivaServices/networkProxyService/getNetworkProxies", {
1284 success: function(data) {
1285 var remoteRepo=new RemoteRepository();
1286 remoteRepo.cronExpression("0 0 08 ? * SUN");
1287 var viewModel = new RemoteRepositoryViewModel(remoteRepo,false,remoteRepositoriesViewModel);
1288 viewModel.networkProxies(mapNetworkProxies(data));
1289 ko.applyBindings(viewModel,mainContent.find("#remote-repository-edit").get(0));
1290 activateRemoteRepositoryFormValidation(true);
1291 activatePopoverDoc();
1295 if ($(e.target).attr("href")=="#remote-repositories-view") {
1296 $("#main-content" ).find("#remote-repository-edit-li" ).find("a").html($.i18n.prop("add"));
1303 loadManagedRepositories=function(successCallBackFn,errorCallBackFn){
1304 $.ajax("restServices/archivaServices/managedRepositoriesService/getManagedRepositories", {
1307 success: successCallBackFn,
1308 error: errorCallBackFn
1312 loadRemoteRepositories=function(successCallBackFn,errorCallBackFn){
1313 $.ajax("restServices/archivaServices/remoteRepositoriesService/getRemoteRepositories", {
1316 success: successCallBackFn,
1317 error: errorCallBackFn
1321 findManagedRepository=function(id,managedRepositories){
1322 var managedRepository=$.grep(managedRepositories,
1324 return repo.id()==id;
1327 return ($.isArray(managedRepository) && managedRepository.length>0) ? managedRepository[0]:new ManagedRepository();