mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
clear view history, closes #393
This commit is contained in:
41
dist/js/ionic-angular.js
vendored
41
dist/js/ionic-angular.js
vendored
@@ -756,17 +756,23 @@ angular.module('ionic.service.view', ['ui.router'])
|
||||
hist.stack.push(viewHistory.histories[rsp.viewId]);
|
||||
}
|
||||
|
||||
viewHistory.currentView = this._getView(rsp.viewId);
|
||||
viewHistory.backView = this._getBackView(viewHistory.currentView);
|
||||
viewHistory.forwardView = this._getForwardView(viewHistory.currentView);
|
||||
this.setNavViews(rsp.viewId);
|
||||
|
||||
hist.cursor = viewHistory.currentView.index;
|
||||
|
||||
return rsp;
|
||||
},
|
||||
|
||||
setNavViews: function(viewId) {
|
||||
var viewHistory = $rootScope.$viewHistory;
|
||||
|
||||
viewHistory.currentView = this._getView(viewId);
|
||||
viewHistory.backView = this._getBackView(viewHistory.currentView);
|
||||
viewHistory.forwardView = this._getForwardView(viewHistory.currentView);
|
||||
|
||||
$rootScope.$broadcast('$viewHistory.historyChange', {
|
||||
showBack: (viewHistory.backView && viewHistory.backView.historyId === viewHistory.currentView.historyId)
|
||||
});
|
||||
|
||||
return rsp;
|
||||
},
|
||||
|
||||
registerHistory: function(scope) {
|
||||
@@ -937,6 +943,31 @@ angular.module('ionic.service.view', ['ui.router'])
|
||||
// make sure the reverse class isn't already added
|
||||
element[0].classList.remove('reverse');
|
||||
}
|
||||
},
|
||||
|
||||
clearHistory: function() {
|
||||
var historyId, x, view,
|
||||
histories = $rootScope.$viewHistory.histories,
|
||||
currentView = $rootScope.$viewHistory.currentView;
|
||||
|
||||
for(historyId in histories) {
|
||||
|
||||
if(histories[historyId].stack) {
|
||||
histories[historyId].stack = [];
|
||||
histories[historyId].cursor = -1;
|
||||
}
|
||||
|
||||
if(currentView.historyId === historyId) {
|
||||
currentView.backViewId = null;
|
||||
currentView.forwardViewId = null;
|
||||
histories[historyId].stack.push(currentView);
|
||||
} else if(histories[historyId].destroy) {
|
||||
histories[historyId].destroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.setNavViews(currentView.viewId);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
41
js/ext/angular/src/service/ionicView.js
vendored
41
js/ext/angular/src/service/ionicView.js
vendored
@@ -200,17 +200,23 @@ angular.module('ionic.service.view', ['ui.router'])
|
||||
hist.stack.push(viewHistory.histories[rsp.viewId]);
|
||||
}
|
||||
|
||||
viewHistory.currentView = this._getView(rsp.viewId);
|
||||
viewHistory.backView = this._getBackView(viewHistory.currentView);
|
||||
viewHistory.forwardView = this._getForwardView(viewHistory.currentView);
|
||||
this.setNavViews(rsp.viewId);
|
||||
|
||||
hist.cursor = viewHistory.currentView.index;
|
||||
|
||||
return rsp;
|
||||
},
|
||||
|
||||
setNavViews: function(viewId) {
|
||||
var viewHistory = $rootScope.$viewHistory;
|
||||
|
||||
viewHistory.currentView = this._getView(viewId);
|
||||
viewHistory.backView = this._getBackView(viewHistory.currentView);
|
||||
viewHistory.forwardView = this._getForwardView(viewHistory.currentView);
|
||||
|
||||
$rootScope.$broadcast('$viewHistory.historyChange', {
|
||||
showBack: (viewHistory.backView && viewHistory.backView.historyId === viewHistory.currentView.historyId)
|
||||
});
|
||||
|
||||
return rsp;
|
||||
},
|
||||
|
||||
registerHistory: function(scope) {
|
||||
@@ -381,6 +387,31 @@ angular.module('ionic.service.view', ['ui.router'])
|
||||
// make sure the reverse class isn't already added
|
||||
element[0].classList.remove('reverse');
|
||||
}
|
||||
},
|
||||
|
||||
clearHistory: function() {
|
||||
var historyId, x, view,
|
||||
histories = $rootScope.$viewHistory.histories,
|
||||
currentView = $rootScope.$viewHistory.currentView;
|
||||
|
||||
for(historyId in histories) {
|
||||
|
||||
if(histories[historyId].stack) {
|
||||
histories[historyId].stack = [];
|
||||
histories[historyId].cursor = -1;
|
||||
}
|
||||
|
||||
if(currentView.historyId === historyId) {
|
||||
currentView.backViewId = null;
|
||||
currentView.forwardViewId = null;
|
||||
histories[historyId].stack.push(currentView);
|
||||
} else if(histories[historyId].destroy) {
|
||||
histories[historyId].destroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.setNavViews(currentView.viewId);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -675,6 +675,18 @@ describe('Ionic View Service', function() {
|
||||
var tab1view2Reg2 = viewService.register(tab1Container);
|
||||
expect(tab1view2Reg2.navAction).toEqual('moveBack');
|
||||
expect(tab1view2Reg2.viewId).toEqual(tab1view2Reg.viewId);
|
||||
|
||||
|
||||
var currentViewId = tab1view2Reg.viewId;
|
||||
expect(rootScope.$viewHistory.histories[tab1view2Reg.historyId].stack.length).toEqual(2);
|
||||
backView = viewService.getBackView();
|
||||
expect(backView).toBeDefined();
|
||||
viewService.clearHistory();
|
||||
expect(rootScope.$viewHistory.histories[tab1view2Reg.historyId].stack.length).toEqual(1);
|
||||
backView = viewService.getBackView();
|
||||
expect(backView).toEqual(null);
|
||||
currentView = viewService.getCurrentView();
|
||||
expect(currentView.viewId).toEqual(currentViewId);
|
||||
}));
|
||||
|
||||
it('should init root viewHistory data', inject(function() {
|
||||
|
||||
@@ -62,6 +62,9 @@
|
||||
<content has-header="true" padding="true">
|
||||
<p>Seriously!? Again?!</p>
|
||||
<p>How about I just give you a password, hows this: <br><code>{{password}}</code></p>
|
||||
<p>
|
||||
<button ng-click="clearViewHistory()">Clear View History</button>
|
||||
</p>
|
||||
<p class="text-center">
|
||||
<a href="#/sign-in">Sign-In</a> -
|
||||
<a href="#/forgot-password">Forgot password</a> -
|
||||
@@ -303,9 +306,12 @@
|
||||
};
|
||||
})
|
||||
|
||||
.controller('ForgotPasswordCtrl', function($scope, $state) {
|
||||
//console.log('ForgotPasswordCtrl');
|
||||
.controller('ForgotPasswordCtrl', function(ViewService, $scope, $state) {
|
||||
$scope.password = Math.round(Math.random() * 10000);
|
||||
|
||||
$scope.clearViewHistory = function() {
|
||||
ViewService.clearHistory();
|
||||
};
|
||||
})
|
||||
|
||||
.controller('AutoListCtrl', function($scope, $state) {
|
||||
|
||||
Reference in New Issue
Block a user