define(["ember","app","moment","rm","fm","../../helpers/fetch_state"],function(a,b,c,d,e,f){return b.GrowthIndexRoute=a.Route.extend({model:function(){var b=this;["fileLocal","finalTemplate","finalTemplateLocal"].forEach(function(a){b.store.unloadAll(a)});var g=[d.getProfiles().then(function(c){var d=[].concat(c).findBy("PersonID",b.get("session.appUser.PersonID"));return d&&0!=d.subFolders.length?(console.log(d),a.RSVP.Promise.all([].concat(d.subFolders).map(function(a){return 2==a.split("-").get("length")?b.store.find("finalTemplateLocal",{_path_:"~/"+a}):void 0}))):[]})];return this.get("session.online")&&g.addObject(this.store.find("finalTemplate",{}).then(function(a){return a.forEach(function(a){b.store.find("finalTemplateLocal",{_path_:"~/%@-%@".fmt(a.get("Term"),a.get("Session"))})}),a})),a.RSVP.Promise.all(g).then(function(d){var g=[];d[0].forEach(function(b){"instance"==a.typeOf(b)&&0<b.get("length")&&g.addObjects(b.map(function(b){return a.Object.create({subscribe:!1,isUpdated:!1,entity:b,state:f.create({state:"loaded"}),schoolyear:"%@年%@学期".fmt(b.get("Term"),"01"==b.get("Session")?"上":"下")})}))});var h=g;return b.get("session.online")&&(h=d[1].map(function(d){var e=g.findBy("entity.id",d.get("id")),h=b.get("session.histories").findBy("id",d.get("Term")+d.get("Session"));return a.Object.create({subscribe:h?h.get("subscribe"):!1,isUpdated:!!(e&&h&&c(e.get("entity.lastpublishtime")).isBefore(h.get("lastpublishtime"))),entity:d,state:f.create({state:e?"loaded":"online"}),schoolyear:"%@年%@学期".fmt(d.get("Term"),"01"==d.get("Session")?"上":"下")})})),a.RSVP.Promise.all(h.map(function(a){return b.get("session.online")||a.set("entity.Coverimg",e.achieveSync({folder:a.get("entity.Term")+"-"+a.get("entity.Session"),url:a.get("entity.Coverimg")})),a.get("state.isLoaded")?b.store.find("fileLocal",{_path_:"~/%@-%@".fmt(a.get("entity.Term"),a.get("entity.Session")),Category:"growth",Tag1:a.get("entity.id")}).then(function(b){return a.set("state.state",b.get("length")==b.filterBy("Status","fetched").get("length")?"fetched":"init"),a}):a}))})}})});